我有三张桌子父母,孩子和资金。
父.rb
class Parent < ApplicationRecord
has_many :children, dependent: :destroy
end
子.rb
class Parent < ApplicationRecord
belongs_to :parent
has_many :fundings, dependent: :destroy
end
资金.rb
class Funding < ApplicationRecord
belongs_to :child
end
孩子和资金之间的连接
create_table "children_fundings", id: false, force: :cascade do |t|
t.integer "child_id", null: false
t.integer "funding_id", null: false
t.index ["child_id", "funding_id"], name:
"index_children_fundings_on_child_id_and_funding_id"
t.index ["funding_id", "child_id"], name:
"index_children_fundings_on_funding_id_and_child_id"
end
加入孩子和父母之间
create_table "children_parents", id: false, force: :cascade do |t|
t.integer "parent_id", null: false
t.integer "child_id", null: false
t.index ["child_id", "parent_id"], name:
"index_children_parents_on_child_id_and_parent_id"
t.index ["parent_id", "child_id"], name:
"index_children_parents_on_parent_id_and_child_id"
end
children 表有 parent_id,fundings 表有 child_id。如何在父母子女和资金表之间创建联接。请帮忙