The Record class represents a single row in a database table. It provides methods for creating, updating, and deleting individual records.
Details
Record is an R6 class that works in conjunction with the TableModel class. Each Record instance corresponds to a single row in the database table represented by its associated TableModel. The class provides methods for CRUD (Create, Read, Update, Delete) operations on individual records.
Methods
initialize(model, data = list())Constructor for creating a new Record instance.
create()Inserts this record into the database.
update()Updates this record in the database.
delete()Deletes this record from the database.
Public fields
modelA TableModel object. Represents the database table this record belongs to.
dataA list. Contains the data for this record, with column names as keys.
relationshipsA list. Contains the relationships defined for this record's model.
Methods
Method new()
Initialize a new Record instance.
Method set_schema()
Update the schema for the underlying model.
Method create()
Insert this record into the database.
Arguments
flush_recordLogical flag determining whether to call `flush()` after insertion, populating the record with server-generated values such as IDENTITY/SERIAL keys and column defaults. Defaults to `NULL`, which flushes when not currently in a transaction. Inside a [with.Engine()] block the default follows that block's `.autoflush` setting, which in turn defaults to the engine's `.autoflush` value; pass `TRUE` explicitly when a later statement needs the generated key. Flushing never commits the transaction.
Method flush()
Flush this record's data to the database.
Method update()
Update this record in the database.
Usage
Record$update(..., .data = list())Method refresh()
Refresh this record from the database.
Method relationship()
Retrieve related records based on a defined relationship.
Arguments
rel_nameThe name of the relationship to query.
...Additional arguments passed to the related model's read method.
Method print()
Print a concise summary of the record, including the table name and field values.