Module: ROM::SQL::Relation::Associations

Defined in:
lib/rom/fmp/relation/associations.rb

Instance Method Summary collapse

Instance Method Details

#association_join(name, options = {}) ⇒ Object

Join configured association.

Uses INNER JOIN type.

Examples:


setup.relation(:tasks)

setup.relations(:users) do
  one_to_many :tasks, key: :user_id

  def with_tasks
    association_join(:tasks, select: [:title])
  end
end


22
23
24
# File 'lib/rom/fmp/relation/associations.rb', line 22

def association_join(name, options = {})
  graph_join(name, :inner, options)
end

#association_left_join(name, options = {}) ⇒ Object

Join configured association

Uses LEFT JOIN type.

Examples:


setup.relation(:tasks)

setup.relations(:users) do
  one_to_many :tasks, key: :user_id

  def with_tasks
    association_left_join(:tasks, select: [:title])
  end
end


43
44
45
# File 'lib/rom/fmp/relation/associations.rb', line 43

def association_left_join(name, options = {})
  graph_join(name, :left_outer, options)
end

#graph(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
# File 'lib/rom/fmp/relation/associations.rb', line 63

def graph(*args)
  __new__(dataset.__send__(__method__, *args))
end

#graph_join(name, join_type, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rom/fmp/relation/associations.rb', line 48

def graph_join(name, join_type, options = {})
  assoc = model.association_reflection(name)

  key = assoc[:key]
  type = assoc[:type]

  if type == :many_to_many
    select = options[:select] || {}
    graph_join_many_to_many(name, assoc, select)
  else
    graph_join_other(name, key, type, join_type, options)
  end
end