I'm not an expert in databases and relational logic and I'm a bit confused about what I have to do in the following situation.
I have a model Expression
where I want to implement a TranslationPair
self referencing many to many relationship.
class Expression
include DataMapper::Resource
has n, :translation_pairs, child_key: [:exp_1_id]
end
class TranslationPair
include DataMapper::Resource
belongs_to :exp_1, 'Expression', key: true
belongs_to :exp_2, 'Expression', key: true
end
The problem is that I would like translation_pairs
relationship to return not only TranslationPair
instances with a given expression in the exp_1
field, but also TranslationPair
instances with the given expression in the exp_2
field (if expression1
is a translation of expression2
, then expression2
is a translation of expression1
). A kind of disjunction in the child_key
option. Something like:
has n, :translation_pairs, child_key: [:exp_1_id] or [:exp_2_id]
Can I implement it directly in the model declaration or I have to implement some custom method?