gpt4 book ai didi

ruby-on-rails-4 - 带有 has_many :through associations 的轨道触摸链

转载 作者:行者123 更新时间:2023-12-01 11:34:07 25 4
gpt4 key购买 nike

使用连接模型,在此示例设置中使用 has_many :through

class Collage
has_many :arrangements
has_many :photos, through: :arrangements

class Photo
has_many :arragements
has_many :collages, through: :arragements
end

class Arragement
belongs_to :photo
belongs_to _collage
end

照片可能会改变尺寸,这会导致拼贴改变

使用 touch: true 不会以这种方式工作,因为链不是“单向向上”,因为 arragement 指向 Photo 拼贴画

我怎样才能使照片更改(即触摸)也能触摸到它的拼贴画?

最佳答案

这是一个更短的版本:

class Photo
has_many :arragements
has_many :collages, through: :arragements

after_save { collages.find_each(&:touch) }
end

关于ruby-on-rails-4 - 带有 has_many :through associations 的轨道触摸链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29215109/

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