私はデータベースとリレーショナル ロジックの専門家ではなく、次の状況で何をしなければならないかについて少し混乱しています。
多対多の関係を参照Expression
する自己を実装したいモデルがあります。TranslationPair
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
問題は、関係がフィールド内の特定の式を持つインスタンスだけでなく、フィールド内の特定の式を持つインスタンスtranslation_pairs
も返すことです (が の翻訳である場合、は の翻訳です)。オプションの選言の一種。何かのようなもの:TranslationPair
exp_1
TranslationPair
exp_2
expression1
expression2
expression2
expression1
child_key
has n, :translation_pairs, child_key: [:exp_1_id] or [:exp_2_id]
モデル宣言で直接実装できますか、それともカスタム メソッドを実装する必要がありますか?