I think this this is a开发者_Python百科 pretty stupid question but I just confused myself
I have several has_many defined. I can reference them in an instance method by saying self.------- If I try to reference via @------ I get nil. Is it just that because it's an ActiveRecord object that it's not available as an instance variable inside the class?
They are not set as instance variables, they are methods. Same as for your properties, you should always access them like this:
self.property
self.read_attribute(:property)
self.write_attribute(:property, value)
They could even be instance variables at the end, but this is an implementation detail and you should always call the code over the well known interface, which is the methods.
associations are methods not instance variables.
精彩评论