DBX::ORM::ModelQuery(Model)
Inherits DBX::Query / Reference / Object
Generic ModelQuery class.
Automatically injected into the models.
If you want to customize the queries of a model, you can define
you own ModelQuery into this model.
class User < DBX::ORM::Model
# ...
class ModelQuery < DBX::ORM::ModelQuery(User)
# A 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
Constructors
new(adapter : DBX::Adapter::Base)
SourceInstance methods
create!(data, returning : DBX::QueryBuilder::OneOrMoreFieldsType = "*")
Creates a new record and returns.
test = Test.create!(data)
puts test.id
Refers to the result of a join in a defined relation property path.
users = User
.find
.rel("groups")
.left_join("groups", "groups.id", "users.group_id")
.to_a
select_all(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : ModelQuery(Model)
Selects the relation fields. This method is automatically called by the methods related to the joins with a model class.
selected_all?(model_class : DBX::ORM::Model.class, table_alias : String | Symbol | Nil = nil) : Bool
Returns true if the relation fields are selected, false otherwise.
See select_rel_fields