我有一组非常大的使用cast_assoc同时保存的互连记录,但是其中一条记录对记录集中的另一部分有一个外键约束。
@primary_key {:id, :binary_id, autogenerate: true}
schema "c_rtu" do
field(:name, :string)
has_many(:communication_maps, CommunicationMap)
has_many(:rtu_streams, RtuStream)
timestamps()
end
@primary_key {:id, :binary_id, autogenerate: true}
schema "c_rtu_stream" do
field(:type, :string)
field(:type_position, :integer)
belongs_to(:template, Template, foreign_key: :template_id)
has_many(:collection_methods, CollectionMethod)
belongs_to(
:c_station_channel,
StationChannel,
foreign_key: :station_channel_id,
on_replace: :update
)
belongs_to(:c_rtu, Rtu, foreign_key: :rtu_id, on_replace: :update)
timestamps()
end
@primary_key {:id, :binary_id, autogenerate: true}
schema "c_collection_method" do
field(:method, :string)
belongs_to(:c_rtu_stream, RtuStream, foreign_key: :rtu_stream_id, on_replace: :update)
belongs_to(:c_section, Section, foreign_key: :section_id, on_replace: :update)
has_many(:instances, Instance)
timestamps()
end
@primary_key {:id, :binary_id, autogenerate: true}
schema "c_instance" do
field(:calculation_method, :string)
belongs_to(:c_field, Field, foreign_key: :field_id, on_replace: :update)
belongs_to(
:c_collection_method,
CollectionMethod,
foreign_key: :collection_method_id,
on_replace: :update
)
timestamps()
end
@primary_key {:id, :binary_id, autogenerate: true}
schema "c_field" do
field(:name, :string)
has_many(:instances, Instance)
belongs_to(
:c_communication_map,
CommunicationMap,
foreign_key: :communication_map_id,
on_replace: :update
)
timestamps()
end
@primary_key {:id, :binary_id, autogenerate: true}
schema "c_communication_map" do
field(:name, :string)
field(:type, :string)
has_many(:fields, Field)
belongs_to(:c_rtu, Rtu, foreign_key: :rtu_id, on_replace: :update)
timestamps()
end我在c_instance -> c_field (c_instance requires c_field c_instance存在)之间有一个单向外键约束。
我目前正在尝试使用c_rtu作为基础来插入它,但我遇到了这样的问题:尽管有一个分支具有c_communication_map和c_field,另一个分支有c_rtu_stream、c_collection_method和c_instance,但即使预先填充了uuid,它也会遇到c_field不存在的约束。
是否存在使用cast_assoc插入的这种循环关系?
发布于 2022-01-31 11:39:04
你能在这里粘贴你的代码吗!!请再次检查模式"d",我认为应该是
schema "d" do
belongs_to :c, C
belongs_to :e, E
end谢谢!!
https://stackoverflow.com/questions/70882877
复制相似问题