Class: Dart::ManyToManyAssociation
Constant Summary
Constants inherited
from Association
Association::MANY_TO_MANY_TYPE, Association::MANY_TO_ONE_TYPE, Association::ONE_TO_MANY_TYPE, Association::ONE_TO_ONE_TYPE
Instance Attribute Summary
Attributes inherited from Association
#model_class, #name, #scope
Instance Method Summary
collapse
Methods inherited from Association
#set_name!, #to_one?
Constructor Details
for an m2m association on users we’d pass in:
left_ass: badge_users.user_id -> users.id
right_ass: badge_users.badge_id -> badges.id
>
many_to_many :badges, join_table: :badge_users
13
14
15
|
# File 'lib/dart/core/many_to_many_association.rb', line 13
def initialize(left_ass, right_ass)
@left_ass, @right_ass = left_ass, right_ass
end
|
Instance Method Details
#associated_table ⇒ Object
25
26
27
|
# File 'lib/dart/core/many_to_many_association.rb', line 25
def associated_table
right_ass.parent_table
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
41
42
43
|
# File 'lib/dart/core/many_to_many_association.rb', line 41
def eql?(other)
join_associations.eql? other.join_associations
end
|
#hash ⇒ Object
46
47
48
|
# File 'lib/dart/core/many_to_many_association.rb', line 46
def hash
join_associations.hash
end
|
#join_associations ⇒ Object
17
18
19
|
# File 'lib/dart/core/many_to_many_association.rb', line 17
def join_associations
[left_ass, right_ass]
end
|
#join_table ⇒ Object
29
30
31
|
# File 'lib/dart/core/many_to_many_association.rb', line 29
def join_table
right_ass.child_table
end
|
#left_foreign_key ⇒ Object
33
34
35
|
# File 'lib/dart/core/many_to_many_association.rb', line 33
def left_foreign_key
left_ass.foreign_key
end
|
#right_foreign_key ⇒ Object
37
38
39
|
# File 'lib/dart/core/many_to_many_association.rb', line 37
def right_foreign_key
right_ass.foreign_key
end
|
#to_s ⇒ Object
50
51
52
|
# File 'lib/dart/core/many_to_many_association.rb', line 50
def to_s
"#{self.class}\n left:#{left_ass}\n right:#{right_ass}"
end
|
#type ⇒ Object
21
22
23
|
# File 'lib/dart/core/many_to_many_association.rb', line 21
def type
MANY_TO_MANY_TYPE
end
|