Initializing aggregated structures


#1

I have a model, Vendor, which belongs_to :account, :visiting_address.
(1…1 for both)

Now, to ‘prevent redundancy’/inconsistencies, the Vendor model doesn’t
have a name attribute, but instead stores it’s name in account.name.
(Should probably be the other way around, but that’s messier)

My controller goes something like this:

@vendor = Vendor.new(:name => whatever)

While vendor has the following methods:

def initialize(*args) # param look reasonable, btw? seems to be
working atm, but…
super
self.account ||= Account.new
self.visiting_address ||= Address.new
end

def name=(name)
self.account ||= Account.new
account.name = name
end

Not the best way to go around this, I’m sure…? Suggestions?