abstract class DBX::ORM::Model
- DBX::ORM::Model
- Reference
- Object
Overview
Base class for all models.
Example, creation of a model for a table users
:
class User < DBX::ORM::Model
adapter :pg
class Schema # < DBX::ORM::Schema#(User)
field id : Int64?
field name : String
field about : String
field age : Int32
end
end
Customize ModelQuery
used by User
model:
class User < DBX::ORM::Model
# ...
class ModelQuery < DBX::ORM::ModelQuery(User)
# Custom select
def select_custom
self.select({:id, :name, :about, :age})
end
end
end
In the model example above, we have added a new method (select_custom
) to `ModelQuery',
which can be used in each query.
user = User.find(id).select_custom.to_o
users = User.find.select_custom.to_a
Defined in:
orm/model.crClass Method Summary
-
.connection : String
DB connection name used by this
Model
instance. -
.db : DB::Database
Returns DB connection name used by this
Model
instance. -
.models
Returns array of all non-abstract subclasses of *DBX::ORM::Model.
Class Method Detail
def self.models
#
Returns array of all non-abstract subclasses of *DBX::ORM::Model.
DBX::ORM::Model.models # => [Contact, Address, User]