TableModel Class
TableModel.Rd
The TableModel class represents a database table in the oRm framework. It manages table structure, fields, relationships, and provides methods for interacting with the database table.
Details
TableModel is a core component of the oRm framework, responsible for:
Defining table structure with columns and relationships
Creating and managing database tables
Providing an interface for CRUD operations on table records
Managing relationships between different tables
Key features:
Dynamic table creation and management
Support for various column types and constraints
Relationship definitions and querying
Record creation and retrieval
Methods
initialize(tablename, engine, ..., .data = list())
Constructor for creating a new TableModel instance.
get_connection()
Retrieve the active database connection from the engine.
generate_sql_fields()
Generate SQL field definitions for table creation.
create_table(if_not_exists = TRUE, overwrite = FALSE, verbose = FALSE)
Create the associated table in the database.
record(..., .data = list())
Create a new Record object associated with this model.
read(..., mode = c("all", "one_or_none", "get"), limit = NULL)
Read records from the table using dynamic filters.
relationship(rel_name, ...)
Query related records based on defined relationships.
print()
Print a formatted overview of the model, including its fields.
Methods
Method new()
Constructor for a new TableModel.
Usage
TableModel$new(tablename, engine, ..., .data = list())
Method generate_sql_fields()
Generate DBI-compatible field definitions from Column and ForeignKey objects, including constraints and SQL clause generation.
Method create_table()
Create the associated table in the database.
Create the associated table in the database.
Method record()
Create a new Record object with this model.
Usage
TableModel$record(..., .data = list())
Method read()
Read records using dynamic filters and return in the specified mode.
Usage
TableModel$read(..., mode = c("all", "one_or_none", "get"), limit = NULL)
Method print()
Print a formatted overview of the model, including its fields.