gpt4 book ai didi

ruby-on-rails-3 - :has_many :through associations two levels deep

转载 作者:行者123 更新时间:2023-12-03 00:48:50 25 4
gpt4 key购买 nike

Project
has_many :tasks

Task
has_many :invoices, :through => :line_items
has_many :line_items

LineItems
belongs_to :invoice
belongs_to :task

Invoice
has_many :tasks, :through=> :line_item
has_many :line_items

我正在尝试从项目 has_many :invoices, :through => :tasks 获取关联

当我尝试时,我得到:

Invalid source reflection macro :has_many :through for has_many :invoices, :through => :tasks. Use :source to specify the source reflection.

我有点不知道这是否可能,如果可以,如何正确使用 :source

最佳答案

Ryan 是对的,这是从 Rails 3.1 开始支持的。摘自发行说明:

带有 :through 选项的关联现在可以使用任何关联作为直通或源关联,包括具有 :through 选项和 has_and_belongs_to_many 关联的其他关联。

来源:http://guides.rubyonrails.org/3_1_release_notes.html

关于ruby-on-rails-3 - :has_many :through associations two levels deep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5240425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com