寻找正确的设置方法audited associated_with
,has_associated_audits
在我的模型中更容易跟踪。
设置:出版商与作者拥有独家经销商。一个作者可以写很多本书。一本书可以有很多作者。一本书有一种类型的书籍装订。一本书装订可以有很多本书。
目标:我希望能够调用 Publisher.find(1).associated_audits 让所有人一举失败。
class Publisher < ActiveRecord::Base
audited
has_associated_audits
has_many :books
end
class Author < ActiveRecord::Base
audited associated_with: :publisher
has_associated_audits
belongs_to :publisher
has_many :author_to_books
has_many :books, through: :author_to_books
end
class AuthorToBook < ActiveRecord::Base
audited associated_with: #????? this is where I need help
has_associated_audits
belongs_to :book
belongs_to :author
end
class Book < ActiveRecord::Base
audited associated_with: #????? this is where I need help
has_associated_audits
has_many :author_to_books
has_many :authors, through: :author_to_books
belongs_to :book_binding_type
end
class BookBindingType < ActiveRecord::Base
audited associated_with: #????? this is where I need help
has_associated_audits
has_many :books
has_many :publishers, through: :books
end
目前我可以打电话Publisher.find(1).associated_audits
,这给了我对 Author 的相关审计。
对于我做的书:Book.joins(:audits).references(:audits).joins(:authors).where(authors: {publisher_id: 1}).map(&:audits)
对于 BookBindingType 我做Book.joins(:audits).references(:audits).joins(:authors).where(authors: {publisher_id: 1}).map(&:audits)
正如您可以猜到的最后两个查询,同时考虑到时间复杂性......当我开始拥有更多记录时,它们仍然需要一些时间来运行。
问题:如何设置????
已审核 gem 的部分以进行跟踪。我知道审计表的多态设置只允许它一次跟踪一个关联记录。那么它甚至可能吗?