module Marten::DB::Model::Persistence::ClassMethods
Defined in:
marten/db/model/persistence.crInstance Method Summary
-
#create(**kwargs)
Creates a model instance and saves it to the database if it is valid.
-
#create(**kwargs, &)
Creates a model instance and saves it to the database if it is valid.
-
#create!(**kwargs)
Creates a model instance and saves it to the database if it is valid.
-
#create!(**kwargs, &)
Creates a model instance and saves it to the database if it is valid.
Instance Method Detail
Creates a model instance and saves it to the database if it is valid.
The model instance is initialized using the attributes defined in the kwargs
double splat argument.
Regardless of whether it is valid or not (and thus persisted to the database or not), the initialized model
instance is returned by this method.
Creates a model instance and saves it to the database if it is valid.
This method provides the exact same behaviour as #create
with the ability to define a block that is
executed for the new object. This block can be used to directly initialize the object before it is persisted
to the database:
Post.create(title: "My blog post") do |post|
post.complex_attribute = compute_complex_attribute
end
Creates a model instance and saves it to the database if it is valid.
The model instance is initialized using the attributes defined in the kwargs
double splat argument.
If the model instance is valid, it is persisted to the database ; otherwise a
Marten::DB::Errors::InvalidRecord
exception is raised.
Creates a model instance and saves it to the database if it is valid.
This method provides the exact same behaviour as #create!
with the ability to define a block that is
executed for the new object. This block can be used to directly initialize the object before it is persisted
to the database:
Post.create!(title: "My blog post") do |post|
post.complex_attribute = compute_complex_attribute
end