Forum: Ruby on Rails Initializing aggregated structures

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5233478c51a92b6a1a5c970cbf3a42f3?d=identicon&s=25 Isak Hansen (Guest)
on 2006-05-23 11:36
(Received via mailing list)
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?
This topic is locked and can not be replied to.