Feature Request- adding 'touch: true' option to :has_many relationship

15 views
Skip to first unread message

Richie

unread,
Mar 17, 2018, 2:08:35 AM3/17/18
to Ruby on Rails: Core
Today I found myself in need of calling the 'touch' method on all instances of one model that are associated via a "has_many" relationship to another model's instance.  I know this is possible with the "belongs_to" relationship by passing the "touch: true" option, so I assumed this would be available on "has_many" as well, however it looks like my assumption is incorrect.

I found a thread from 2010 which proposes this exact feature, and it appears the consensus at the time was that the drawbacks to the proposal would be prohibitive, and that sufficient alternatives already exist (such as an "after_save" callback which calls "touch" instead).  I propose that this alternative suffers from the same issues, in addition to which it also suffers from being non-intuitive from an API standpoint.  In other words, there may be other developers like me who see that :belongs_to allows a touch option, and who therefore assume the reverse is also true.

In case things have changed since 2010, and in the interest of making the API for "has_many" and "belongs_to" less surprising and more uniform, would the current core maintainers be willing to re-open this discussion?  I'm happy to provide a proposal for discussion along with supporting rationale.

Thanks!

Richie
Reply all
Reply to author
Forward
0 new messages