我正在一个数据模型上工作,该数据模型具有跟踪图表各组成部分的元素,并且需要能够拥有所有子元素和父元素。但是,当我尝试保存错误时,我列出了以下模型。
class Element
include DataMapper::Resource
property :element_id, Serial, :key => true
has n, :attributions, :child_key => [:child_id]
has n, :parents, self, :through => :attributions, :via => :parent
end
class Attribution
include DataMapper::Resource
property :attribution_id, Serial, :key => true
belongs_to :child, 'Element'
belongs_to :parent, 'Element'
end
post '/test/:id/attribution/:element_id/addattribution' do
@toc = Theoryofchange.get(params[:id])
@parent_element = Element.get(params[:element_id])
@child_element = Element.get(params[:child])
attribution = Attribution.new
attribution.child = @child_element
attribution.parent = @parent_element
attribution.save
end
当我保存表单时,会出现以下错误。
2018-10-08 11:00:52-DataMapper :: SaveFailureError-Attribution#save返回false,未保存Attribution:
我已经按照文档进行了自我参照关系的研究,但是显然我缺少一些东西。