Add the following code to your project's shard.yml under:
to use in production
- OR -
development_dependencies to use in development
Extending ActiveModel for attribute definitions and validations
Register callbacks for
destroy by setting the corresponding before/after callback handler.
class ModelWithCallbacks < RethinkORM::Base attribute address : String attribute age : Int32 = 10 before_create :set_address after_update :set_age before_destroy do self.name = "joe" end def set_address self.address = "23" end def set_age self.age = 30 end end
Set associations with
Access children in parent by accessing the method correpsonding to the pluralised child.
Children collection method name is generated by dumb pluralisation (appending an s).
Optionally set children collection name in
has_many by setting
class Parent < RethinkORM::Base attribute name : String has_many Child, collection_name: "children" end class Child < RethinkORM::Base attribute age : Int32 belongs_to Parent has_many Pet end class Pet < RethinkORM::Base attribute name : String belongs_to Child end parent = Parent.new(name: "Phil") parent.children.empty? # => true child = Child.new(age: 99) child.pets.empty? # => true
dependent param in the association definition macros defines the fate of the association on model destruction.
:delete ensure destruction of association dependents.