Charlie Hubbard
2006-Aug-24 15:41 UTC
[Rails] How does the save method work with has_many? Code Details.
Hi, I''m trying to fix a plugin that is adding the equivalent of a has_many relationship to an object. Here is what I understand has_many does and how it mixins in with the concrete object. If I have an object Foo and it has_many Bars then here is the code: class Foo < ActiveRecord::Base has_many :bars end What that does is add several methods to manage that relationship, and it stores an array under the @bars instance variable that stores the individual instances of Bar. Now regular fields from the database are stored in @attributes instance variable. What I''m a little fuzzy on is how does save know to commit both attributes and the @bars instance variable when the user calls save method? Effectively I''m trying to modify a plugin so that it will cache this collection similiar to has_many, and it will commit that collection when you save. Right now it is always commiting and always reading from the datbase and stores nothing in memory. Charlie -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---