Presently, it is only possible to pre-select direct relations (such as records targeted by many-to-one or one-to-one fields) through the use of #join when defining query sets. While reverse relations defined in the context of many-to-one fields could be prefetched through the use of the upcoming #prefetch helper (#104), pre-selecting records targeted by one-to-one reverse relations is something that should be possible through the use of the existing #join helper.
For example, given the following definition:
class User < Marten::Model
field :id, :big_int, primary_key: true, auto: true
field :username, :string, max_size: 255
end
class Profile < Marten::Model
field :id, :big_int, primary_key: true, auto: true
field :user, :one_to_one, to: User, related: :profile
end
It should be possible to retrieve all the users and their associated profiles in one query with:
Description
Presently, it is only possible to pre-select direct relations (such as records targeted by many-to-one or one-to-one fields) through the use of
#join
when defining query sets. While reverse relations defined in the context of many-to-one fields could be prefetched through the use of the upcoming#prefetch
helper (#104), pre-selecting records targeted by one-to-one reverse relations is something that should be possible through the use of the existing#join
helper.For example, given the following definition:
It should be possible to retrieve all the users and their associated profiles in one query with: