Hey guys and gals, I have the following object that has acts_as_versioned: class Note < ActiveRecord::Base acts_as_versioned belongs_to :user end The schema for my notes table is as follows: create_table :notes, :force => true do |t| t.column :id, :integer t.column :noteshare_id, :integer t.column :user_id, :integer t.column :title, :string t.column :content, :text t.column :created_at, :datetime t.column :updated_at, :datetime t.column :version, :integer end Note.create_versioned_table Now I want to be able to do: <% @notes.versions.each do |version| %> <%= version.user.fullname %><br/> <% end %> But I can''t! User is not associated with versions. How can I associate it? Thanks for your help :-). This has been bugging me for a long time. John Kopanas http://www.kopanas.com ====================================================================http://www.soen.info - source of the freshest software engineering information on the net http://cusec.soen.info - software engineering conference
On Feb 13, 2006, at 4:48 PM, John Kopanas wrote:> Now I want to be able to do: > > <% @notes.versions.each do |version| %> > <%= version.user.fullname %><br/> > <% end %> > > But I can''t! > > User is not associated with versions. How can I associate it?User.find(version.user_id).fullname -- -- Tom Mornini
I think what you''ll need to do is create a DocumentVersion model and adds a belongs_to to that. I think it would work then. On Monday, February 13, 2006, at 7:48 PM, John Kopanas wrote:>Hey guys and gals, > >I have the following object that has acts_as_versioned: > >class Note < ActiveRecord::Base > acts_as_versioned > belongs_to :user >end > >The schema for my notes table is as follows: > > create_table :notes, :force => true do |t| > t.column :id, :integer > t.column :noteshare_id, :integer > t.column :user_id, :integer > t.column :title, :string > t.column :content, :text > t.column :created_at, :datetime > t.column :updated_at, :datetime > t.column :version, :integer > end > Note.create_versioned_table > >Now I want to be able to do: > > <% @notes.versions.each do |version| %> > <%= version.user.fullname %><br/> > <% end %> > >But I can''t! > >User is not associated with versions. How can I associate it? > >Thanks for your help :-). This has been bugging me for a long time.-- Posted with http://DevLists.com. Sign up and save your time!
On 2/13/06, John Kopanas <john@protoseinc.com> wrote:> Hey guys and gals, > > I have the following object that has acts_as_versioned: > > class Note < ActiveRecord::Base > acts_as_versioned > belongs_to :user > end > > The schema for my notes table is as follows: > > create_table :notes, :force => true do |t| > t.column :id, :integer > t.column :noteshare_id, :integer > t.column :user_id, :integer > t.column :title, :string > t.column :content, :text > t.column :created_at, :datetime > t.column :updated_at, :datetime > t.column :version, :integer > end > Note.create_versioned_table > > Now I want to be able to do: > > <% @notes.versions.each do |version| %> > <%= version.user.fullname %><br/> > <% end %> > > But I can''t! > > User is not associated with versions. How can I associate it? > > Thanks for your help :-). This has been bugging me for a long time. > > John Kopanas > http://www.kopanas.comTry this: class Note < ActiveRecord::Base acts_as_versioned do belongs_to :user end end This is a fairly new feature that I''ve added. I haven''t bothered to update the gem or rdocs though, plugins are more agile. And I don''t have that stuff all set up on my powerbook yet. I''m quite sure this will require edge rails too. Note: this creates an extension module that will be applied to both Note and Note::Version. No need to call belongs_to on the model then. http://techno-weenie.net/svn/projects/plugins/acts_as_versioned/lib/acts_as_versioned.rb -- Rick Olson http://techno-weenie.net
On 14 Feb 2006 01:05:16 -0000, Joshua Schairbaum <devlists-rubyonrails@devlists.com> wrote:> I think what you''ll need to do is create a DocumentVersion model and > adds a belongs_to to that. I think it would work then.If you want to modify the versioned class, try this: class Note < ActiveRecord::Base belongs_to :user end Note.versioned_class.class_eval do belongs_to :user end This will work on older versions of acts_as_versioned too. -- Rick Olson http://techno-weenie.net
That is great Rick. I can''t test it though because my application for some odd reason does not like edge rails. I am always getting unitialized constant. Any insight into that? :-) On 13-Feb-06, at 8:06 PM, Rick Olson wrote:> On 2/13/06, John Kopanas <john@protoseinc.com> wrote: >> Hey guys and gals, >> >> I have the following object that has acts_as_versioned: >> >> class Note < ActiveRecord::Base >> acts_as_versioned >> belongs_to :user >> end >> >> The schema for my notes table is as follows: >> >> create_table :notes, :force => true do |t| >> t.column :id, :integer >> t.column :noteshare_id, :integer >> t.column :user_id, :integer >> t.column :title, :string >> t.column :content, :text >> t.column :created_at, :datetime >> t.column :updated_at, :datetime >> t.column :version, :integer >> end >> Note.create_versioned_table >> >> Now I want to be able to do: >> >> <% @notes.versions.each do |version| %> >> <%= version.user.fullname %><br/> >> <% end %> >> >> But I can''t! >> >> User is not associated with versions. How can I associate it? >> >> Thanks for your help :-). This has been bugging me for a long time. >> >> John Kopanas >> http://www.kopanas.com > > Try this: > > class Note < ActiveRecord::Base > acts_as_versioned do > belongs_to :user > end > end > > This is a fairly new feature that I''ve added. I haven''t bothered to > update the gem or rdocs though, plugins are more agile. And I don''t > have that stuff all set up on my powerbook yet. I''m quite sure this > will require edge rails too. > > Note: this creates an extension module that will be applied to both > Note and Note::Version. No need to call belongs_to on the model then. > > http://techno-weenie.net/svn/projects/plugins/acts_as_versioned/lib/ > acts_as_versioned.rb > > -- > Rick Olson > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsJohn Kopanas http://www.kopanas.com ====================================================================http://www.soen.info - source of the freshest software engineering information on the net http://cusec.soen.info - software engineering conference
On 2/13/06, John Kopanas <john@protoseinc.com> wrote:> That is great Rick. I can''t test it though because my application > for some odd reason does not like edge rails. I am always getting > unitialized constant. Any insight into that? :-)Well, my apps get it if they''re not on edge rails :) -- Rick Olson http://techno-weenie.net
This will work for me. My natural followup questions to this is how can two versioned classes be linked together? Assuming Parent has_many Children and a Child belongs_to Parent, I would want Parent_version to have_many Children_Version and a Child_Version to belong_to Parent_version. Is this easily doable ? Regards, Don Rick Olson wrote:> On 14 Feb 2006 01:05:16 -0000, Joshua Schairbaum > <devlists-rubyonrails@devlists.com> wrote: >> I think what you''ll need to do is create a DocumentVersion model and >> adds a belongs_to to that. I think it would work then. > > If you want to modify the versioned class, try this: > > class Note < ActiveRecord::Base > belongs_to :user > end > > Note.versioned_class.class_eval do > belongs_to :user > end > > This will work on older versions of acts_as_versioned too. > > -- > Rick Olson > http://techno-weenie.net-- Posted via http://www.ruby-forum.com/.
On 2/21/06, don mc <don.mcclean@gmail.com> wrote:> This will work for me. My natural followup questions to this is > how can two versioned classes be linked together? Assuming Parent > has_many Children and a Child belongs_to Parent, I would want > Parent_version to have_many Children_Version and a Child_Version > to belong_to Parent_version. Is this easily doable ? > > Regards, > DonSure, just reopen the class at the bottom of the file. class Foo < AR::Base acts_as_versioned end Foo.versioned_class.class_eval do # extra stuff end -- Rick Olson http://techno-weenie.net
Rick Olson wrote:> Try this: > > class Thing < ActiveRecord::Base > acts_as_versioned do > belongs_to :user > end > endI think I must be misunderstanding something, or doing something wrong. When I modified my acts_as_versioned class (in my case "Thing") as described above, I get a NoMethodError: undefined method ''belongs_to'' for #<Module:0x2791c00>. Alternatively, I tried>class Thing < ActiveRecord::Base > belongs_to :user >end > >Thing.versioned_class.class_eval do > belongs_to :user >endand while there are no errors, eager-loading doesn''t happen when I''m viewing one of my versions. I''m using EdgeRails, and version 0.5.1 (Oct 5, 2006) of the AAV plugin. If it makes a difference, my user model is provided by ActsAsAuthenticated, and the related fields in my Thing model (created_by, and updated_by) are being handled dynamically by the userstamp plugin ( http://delynnberry.com/projects/userstamp/ ). If there are any pertinent details that I''m leaving out, please let me know! Any pointers anyone could offer would be very much appreciated! -- 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 -~----------~----~----~----~------~----~------~--~---
Gwen Campbell wrote:> I think I must be misunderstanding something, or doing something wrong.Murphy must have a law, yes, stating that one will only realize the solution *after* publicly asking for help :) The issue, of course, was that I was not specifying the foreign_key in the versioned table. Thing.versioned_class.class_eval do belongs_to :created_by, :class_name => "User", :foreign_key => "created_by" belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by" end is what was needed. I''m still not clear why class Thing < ActiveRecord::Base acts_as_versioned do belongs_to :created_by, :class_name => "User", :foreign_key => "created_by" belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by" end end doesn''t do the same, but that''s academic at this point. :) -- 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 -~----------~----~----~----~------~----~------~--~---