Skip to contents

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

model

A TableModel object. Represents the database table this record belongs to.

data

A list. Contains the data for this record, with column names as keys.

relationships

A list. Contains the relationships defined for this record's model.

Methods


Method new()

Initialize a new Record instance.

Usage

Record$new(model, ..., .data = list())

Arguments

model

A TableModel object representing the database table.

...

Named arguments corresponding to field values for the record.

.data

A named list of field values (alternative to ...).

Returns

A new Record instance.


Method create()

Insert this record into the database.

Usage

Record$create()

Returns

Invisible NULL


Method update()

Update this record in the database.

Usage

Record$update(..., .data = list())

Arguments

...

Named arguments corresponding to field values to update.

.data

A named list of field values to update (alternative to ...).

Returns

The Record instance (invisibly).


Method delete()

Delete this record from the database.

Usage

Record$delete()

Returns

Invisible NULL


Method refresh()

Refresh this record from the database.

Usage

Record$refresh()

Returns

The Record instance (invisibly).


Method relationship()

Retrieve related records based on a defined relationship.

Usage

Record$relationship(rel_name, ...)

Arguments

rel_name

The name of the relationship to query.

...

Additional arguments passed to the related model's read method.

Details

This method returns related records based on the relationship type: - For 'one_to_one' and 'many_to_one' relationships, it returns a single Record object or NULL. - For 'one_to_many' and 'many_to_many' relationships, it returns a list of Record objects.

Returns

A single Record, a list of Records, or NULL, depending on the relationship type.


Method print()

Usage

Record$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

Record$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.