edit: Обновлен вопрос, чтобы показать мое использование :child_key => [:comparison_id]
, как предлагается в комментарии.
У меня есть две модели, которые выглядят так:
class Comparison
include DataMapper::Resource
property :id, Serial
end
class Msrun
include DataMapper::Resource
property :id, Serial
property :name, String
end
Сравнение происходит из сравнения двух наборов мсрунов. Я думал, что представлю это через два отношения «многие ко многим» от «Сравнения» до «Мсрун», но я бьюсь головой об стену о том, как это сделать в DataMapper. Я знаю, что отношения многие-ко-многим доступны, добавив что-то вроде этого:
has n, :whatevers, :through => Resource
Однако между этими двумя моделями будет установлено только одно отношение «многие ко многим». Я также попытался создать две модели соединения и вручную указать отношения, а также вручную указать дочерний ключ для каждого отношения следующим образом:
# Join model for the comparison-msrun many-to-many relationship.
class First
include DataMapper::Resource
belongs_to :msrun, :key => true
belongs_to :comparison, :key => true
end
# Join model for the comparison-msrun many-to-many relationship.
class Second
include DataMapper::Resource
belongs_to :msrun, :key => true
belongs_to :comparison, :key => true
end
class Comparison
include DataMapper::Resource
property :id, Serial
has n, :firsts
has n, :msrun_firsts, 'Msrun', :through => :firsts, :child_key => [:msrun_id]
has n, :seconds
has n, :msruns_seconds, 'Msrun', :through => :seconds, :child_key => [:msrun_id]
end
class Msrun
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :firsts
has n, :comparison_firsts, 'Comparison', :through => :firsts, :child_key => [:comparison_id]
has n, :seconds
has n, :comparison_seconds, 'Comparison', :through => :seconds, :child_key => [:comparison_id]
end
Запуск automigrate
приводит к следующей ошибке:
rake aborted!
No relationships named msrun_firsts or msrun_first in First
Что я здесь не так делаю? Как я могу сделать эту работу?