Hi Everyone, I am attempting to version my model, so I can go back through time, as well as offer an audit trail. I have attempted to use acts_as_versioned (http://wiki.rubyonrails.org/ rails/pages/ActsAsVersioned), but the issue with this is the associated models, which it does not support. Here is an example of what my model looks like: company has_many phone_numbers company has_many contacts company has_one status .... and so on I need to be able to have the plugin version each associated model automatically. Does anyone know of a solution for this? Thanks for your help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Lundie wrote:> Hi Everyone,> company has_many phone_numbers > company has_many contacts > company has_one status > .... and so on > > I need to be able to have the plugin version each associated model > automatically. > > Does anyone know of a solution for this?I haven''t heard of anything like that. But I can''t imagine you can adapt ActsAsVersioned to your needs, because it works with a different table, so associations are going to break. Perhaps a more bespoke solution; add_column :companies, :versioned_at, :datetime, :default => nil add_column :companies, :version_of, :integer, :default => nil Now when we "version" it, we go. class Company has_many :versions, :class_name => "Company", :foreign_key => "version_id", :order => "companies.versioned_at DESC" belongs_to :version_of, :class_name => "Company" def version! transaction do versioned = Company.new(self.attributes.merge(:versioned_at => Time.now, :version_of => self.id) # go through each association and clone the attribs, pointing at versioned self.phone_numbers.each do |phone_number| versioned.phone_numbers.build(phone_number.attributes) end ... self.save! end end end something like that maybe? (totally untested code) Matthew Rudy Jacobs http://funchforlunch.blogspot.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew Rudy Jacobs wrote:> add_column :companies, :versioned_at, :datetime, :default => nil > add_column :companies, :version_of, :integer, :default => niland, if you did this, you''d have to remember only to look at "live versions" class Company named_scope :live, :conditions => {:version_of => nil} end and then always refer to; Company.live.find(params[:id]) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---