module Jennifer::QueryBuilder::Joining

Direct including types

Defined in:

jennifer/query_builder/joining.cr

Instance Method Summary

Instance Method Detail

def join(source : Class, table_alias : String? = nil, type = :inner, relation : String? = nil, &) #

Adds JOIN of the source's class table to the request.

You can pass table alias which will be automatically used by given expression builder.

Method block provides two arguments:

  • expression builder for the table that is mentioned in the FROM clause;
  • expression builder for the table that is joined.

At the same time block is executed in context of joined table.

Contact.all.join(Address) { |t| _contact_id == t._id }
# => JOIN addresses ON addresses.contact_id = contacts.id

Contact.all.join(Address, "some_table") { |t| _contact_id == t._id }
# => JOIN addresses some_table ON some_table.contact_id = contacts.id

[View source]
def join(source : String, table_alias : String? = nil, type = :inner, relation : String? = nil, &) #

Adds JOIN of source table to the request.

Contact.all.join("addresses") { |t| _contact_id == t._id }
# => JOIN addresses ON addresses.contact_id = contacts.id

[View source]
def join(source : Query, table_alias : String, type = :inner, &) #

Adds JOIN of source query to the request.

Contact.all.join(Address.all, "some_table") { |t| _contact_id == t._id }
# => JOIN (SELECT addresses.* FROM addresses) some_table ON some_table.contact_id = contacts.id

[View source]
def lateral_join(source : Query, table_alias : String, type = :inner, &) #

Adds JOIN LATERAL of source query to the request.

Contact.all.lateral_join(Address.all, "some_table") { |t| _contact_id == t._id }
# => JOIN LATERAL (SELECT addresses.* FROM addresses) some_table ON some_table.contact_id = contacts.id

[View source]
def left_join(source : Class, table_alias : String? = nil, &) #

Adds LEFT JOIN of the source's class table to the request.

Alias for #join(source, table_alias, :left).


[View source]
def left_join(source : String, table_alias : String? = nil, &) #

Adds LEFT JOIN of source table to the request.

Alias for #join(source, table_alias, :left).


[View source]
def right_join(source : Class, table_alias : String? = nil, &) #

Adds RIGHT JOIN of the source's class table to the request.

Alias for #join(source, table_alias, :right).


[View source]
def right_join(source : String, table_alias : String? = nil, &) #

Adds RIGHT JOIN of source table to the request.

Alias for #join(source, table_alias, :right).


[View source]