Rome::Model
Inherits Rome::Serialization < Rome::Associations < Reference < Object
Constructors
Creates a record in database with the specified attributes. For example:
user = User.create(name: "julien", group_id: 2)
# => User(id: 1, name: "julien", group_id: 2)
Automatically fills the created_at and updated_at columns if they
exist and are nil.
Class methods
Deletes one or many records identified by ids from the database.
User.delete(1)
User.delete(1, 2, 3)
Updates one or many records identified by id in the database.
User.update(1, { name: julien })
User.update([1, 2, 3], { group_id: 2 })
Updates one or many records identified by id in the database.
User.update(1, { name: julien })
User.update([1, 2, 3], { group_id: 2 })
Instance methods
Generic accessor for an attribute. Only valid for known columns. Raises a
Rome::MissingAttribute exception when the attribute is undefined (e.g.
not loaded from the database).
Generic accessor for an attribute or extraneous attribute. Raises a
Rome::MissingAttribute exception when the attribute is undefined (e.g.
not loaded from the database).
Generic setter for an attribute. Only valid for known columns.
Generic accessor for an attribute. Returns nil when the attribute is
undefined (e.g. not loaded from the database).
Generic accessor for an attribute or extraneous attribute. Returns nil
when the attribute is undefined (e.g. not loaded from the database).
Sets many attributes at once. For example:
user = User.find(1)
user.attributes = {
group_id: 2,
name: "julien",
}
user.group_id # => 2
user.name # => "julien"
Returns true if any attribute has changed since this model was initialized or last saved.
Tell that all changes have been applied to the database, thus clearing all change information.
Deletes the record and dependent associations from the database. Marks the record as deleted.
Returns true is the record is known to exist in the database (has either been loaded or saved and not deleted).
Reloads a record from the database. This will reset all changed attributes and all change information.
Restores all dirty attributes to their pristine value. Eventually clears change information.
Persists the record into the database. Either creates a new row or updates an existing row.
user = User.new(name: "julien", group_id: 2)
user.save # => INSERT
user.name = "alice"
user.save # => UPDATE
Updates a record into the database, optionally setting the specified attributes if present.
Automatically updates the updated_at column if it exists.
Raises a ReadOnlyRecord exception if the record has been deleted.
Macros
Declares the model schema. For example:
class User < Rome::Model
columns(
id: {type: Int32, primary_key: true},
group_id: {type: UUID, null: true},
name: {type: String},
)
end
Available options:
type—the column type (required);primary_key—whether the column is the table primary key (default: false);null—whether the column accepts NULL values (default: false).converter—specify a converter type that must implement.from_rs(DB::ResultSet)and should implement.from_json(JSON::PullParser).