Hi,
Imagine you have a model Guy. Pick a guy from your table. Maybe he is married and have children (single guys can't have children, can they?). So your are tempted to write:
class Guy < ActiveRecord::Base has_many :children end
But if he is single, he can't have children. So you wan't to write:
class Guy < ActiveRecord::Base if self.single has_many :children else has_one :child end end
This could work: in fact has_* is just a macro for a bunch of specific define_method. I am wrong?
But it doesn't: the loading of the class fails claiming for NoMethodError: undefined method `single' I don't understand: does AR loads relationships before defining accessors? And if I force attr_accessor :single, assuming AR will override it, I've got the same error. Does he parses the whole class seeking for relationship first?
Thanks for your help,