On Feb 9, 4:07 pm, John Firebaugh <[email protected]> wrote: > Rails edge has a new feature for associations, where accessors for > associated objects check for staleness caused by updating foreign key > attributes directly: > > album = Album.first > album.artist_id #=> 1 > album.artist # caches associated artist > album.artist_id = 2 > album.artist # reloads associated artist > > What do you think about adding this feature to sequel? I've encountered > several bugs that were caused by forgetting to manually reload an > association after the foreign key was changed, so I would find it useful.
I was planning on adding the feature as a plugin before 3.21.0. It's fairly simple. Use an anonymous module for each class, and for every many_to_one call, add the foreign key setter method to the anonymous module to clear the association cache for the association if the value has changed (calling super in either case). That way you can just do "Sequel::Model.plugin :stale_associations" before defining your models and automatically get the behavior. Anyone who wants to implement it first is welcome to submit a patch/ pull request. :) Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
