Forum: Ruby on Rails ActiveRecord customer model with multiple previous addresses

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jason Gilstrap (Guest)
on 2006-01-11 17:06
(Received via mailing list)
I would appreciate some advice or ideas on the best way to design my
data model for keeping track of multiple addresses for one customer.
Each customer should have one active address but I want to keep
previous addresses as well.

For instance, for each customer it would be nice to see the current
address using something like Customer.current_address put also be able
to get an array of previous addresses (ones that are not marked
active) using something like Customer.previous_addresses.

Any ideas on the best way to  handle this?

class Customer < ActiveRecord::Base

class Address < ActiveRecord::Base

Thanks in advance,

-Jason Gilstrap
Alex Y. (Guest)
on 2006-01-11 17:34
(Received via mailing list)
Jason Gilstrap wrote:
> Any ideas on the best way to  handle this?

More specifically:

class Customer < ActiveRecord::Base
   has_many :addresses, :order => 'position'
   def current_address
   def past_addresses

class Address < ActiveRecord::Base
   belongs_to :customer
   acts_as_list :scope => :customer

Although that'll get a little hairy if they've got more than one active
address at once (work/home, for example)...
This topic is locked and can not be replied to.