Vestal Versions Related Records

I need to keep version of a model Client:

  has_many :product_clients   has_many :products, :through => :product_clients

The question is what is the best way of saving versions of the association. Can I make the association using the client.version.id rather than the client.id? Or should I use a bit mask?

Any thoughts much appreciated,

Mike

mikej wrote:

I need to keep version of a model Client:

  has_many :product_clients   has_many :products, :through => :product_clients

The question is what is the best way of saving versions of the association. Can I make the association using the client.version.id rather than the client.id? Or should I use a bit mask?

Any thoughts much appreciated,

Mike

What about adding a datetime start and a datetime end to the product_clients model - expand it out to a full join table with additional attributes? Don't delete the relationship, just end it. Then you could view which products a client had on any given date, today or in the past.

That would work. I like the idea of making my clients serial monogamists.

However, it is a bit of a faff having to pass a date every time, or perhaps I could write this into the has_many relationship. Am I missing something?

I've just added a version_id (populated with the version number) to the product_clients and added to the association:

  has_many :product_clients :dependent => :destroy, :conditions => 'product_clients.version_id = #{self.send("version")}'   has_many :products, :through => :product_clients

Does this seem sensible?

Mike