bramski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-09 20:28 UTC
How to use Single Table Inheritance with Modules
So, I have a table... events ==========id int type varchar(255) data text Which I''m using to log some simple system events... class Event < ActiveRecord::Base end I''d like to file quite a lot of events in here, and load them later into a general parsing and display system for the events. However, what I''d really like to do is: class Component::FooBarEvent < ActiveRecord::Base end new_event = Component::FooBarEvent.create :data => {"msg" =>"Hello world"} assert( new_event == Event.find_by_id(new_event.id) ) instead what I get is... LoadError: Expected /home/bramski/source/trunk/config/../app/models/ events/component_events/foo_bar_event.rb to define FooBarEvent If I look in the SQL I see... SQL (0.000269) INSERT INTO events ( `type`, `data`, `eventable1_type`, `foreign_id`) VALUES(''TestEvent'', ''--- \nmsg: Hello world\n'') Now.. I should never see the above LoadError for the missing constant as Component::FooBarEvent is already defined. What is confusing here is, why is rails putting in the unqualified constant for the object (FooBarEvent) as opposed to the fully qualified constant name (Component::FooBarEvent). Is there a way to get rails to store and load Component::FooBarEvent as the type, rather than just FooBarEvent? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, How about either renaming Component::FooBarEvent to ComponentEvents::FooBarEvent or renaming the directory component_events to component ? Cheers, Yuri On 5/9/07, bramski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <bramski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > So, I have a table... > > events > ==========> id int > type varchar(255) > data text > > Which I''m using to log some simple system events... > > class Event < ActiveRecord::Base > end > > I''d like to file quite a lot of events in here, and load them later > into a general parsing and display system for the events. However, > what I''d really like to do is: > > class Component::FooBarEvent < ActiveRecord::Base > end > > new_event = Component::FooBarEvent.create :data => {"msg" =>"Hello > world"} > assert( new_event == Event.find_by_id(new_event.id) ) > > instead what I get is... > LoadError: Expected /home/bramski/source/trunk/config/../app/models/ > events/component_events/foo_bar_event.rb to define FooBarEvent > > If I look in the SQL I see... > SQL (0.000269) INSERT INTO events ( `type`, `data`, > `eventable1_type`, `foreign_id`) VALUES(''TestEvent'', ''--- \nmsg: > Hello world\n'') > > Now.. I should never see the above LoadError for the missing constant > as Component::FooBarEvent is already defined. What is confusing here > is, why is rails putting in the unqualified constant for the object > (FooBarEvent) as opposed to the fully qualified constant name > (Component::FooBarEvent). > > Is there a way to get rails to store and load Component::FooBarEvent > as the type, rather than just FooBarEvent? > > > > >-- Best regards, Yuri Leikind --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
bramski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-11 00:17 UTC
Re: How to use Single Table Inheritance with Modules
That doesn''t really do anything, I still don''t get ActiveRecord storing as "type" => "ComponentEvents::FooBarEvent", I get "type" => "FooBarEvent", and rails is unable to locate the class "Object::FooBarEvent" because it''s "ComponentEvents::FooBarEvent". On May 10, 4:12 am, "Yuri Leikind" <yuri.leik...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, > > How about either > > renaming Component::FooBarEvent to ComponentEvents::FooBarEvent > > or > > renaming the directory component_events to component ? > > Cheers, > Yuri > > On 5/9/07, bram...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <bram...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > So, I have a table... > > > events > > ==========> > id int > > type varchar(255) > > data text > > > Which I''m using to log some simple system events... > > > class Event < ActiveRecord::Base > > end > > > I''d like to file quite a lot of events in here, and load them later > > into a general parsing and display system for the events. However, > > what I''d really like to do is: > > > class Component::FooBarEvent < ActiveRecord::Base > > end > > > new_event = Component::FooBarEvent.create :data => {"msg" =>"Hello > > world"} > > assert( new_event == Event.find_by_id(new_event.id) ) > > > instead what I get is... > > LoadError: Expected /home/bramski/source/trunk/config/../app/models/ > > events/component_events/foo_bar_event.rb to define FooBarEvent > > > If I look in the SQL I see... > > SQL (0.000269) INSERT INTO events ( `type`, `data`, > > `eventable1_type`, `foreign_id`) VALUES(''TestEvent'', ''--- \nmsg: > > Hello world\n'') > > > Now.. I should never see the above LoadError for the missing constant > > as Component::FooBarEvent is already defined. What is confusing here > > is, why is rails putting in the unqualified constant for the object > > (FooBarEvent) as opposed to the fully qualified constant name > > (Component::FooBarEvent). > > > Is there a way to get rails to store and load Component::FooBarEvent > > as the type, rather than just FooBarEvent? > > -- > Best regards, > Yuri Leikind--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---