ActiveRecord customer model with multiple previous addresses


#1

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
end

class Address < ActiveRecord::Base
end

Thanks in advance,

-Jason Gilstrap
removed_email_address@domain.invalid


#2

Jason Gilstrap wrote:

Any ideas on the best way to handle this?
acts_as_list.

More specifically:

class Customer < ActiveRecord::Base
has_many :addresses, :order => ‘position’
def current_address
self.addresses.last
end
def past_addresses
self.addresses[0…-2]
end
end

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

Although that’ll get a little hairy if they’ve got more than one active
address at once (work/home, for example)…