Duane Morin
2009-Jan-28 23:40 UTC
Can I "fake" an object model on top of a flat ActiveRecord?
This might be a painfully bad idea, but it''s gotten me curious. I have a generic object Node, which has a name attribute. Say for example that one of the names is "Widget". What I''m wondering is, is there a way to manipulate ActiveRecord to make a class named Widget, that behaves exactly like a Node with the only difference being that all operations only work on the condition (name="Widget") is true? I can do a simple class Widget < Node to get it started, but I''m looking for what the next line would be, where I can specify the global condition. In all other cases, History : The database itself is generated rather, well, generically by scanning a file where I don''t know the nature of the content beyond simple node relationships (i.e. I don''t know ahead of time all values for "name"). However, I''m thinking that after the flat data storage portion is taken care of I could go in and maybe write some sort of generator for myself that would build up the Ruby classes to deal with the database, and hide the whole thing. -- 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 -~----------~----~----~----~------~----~------~--~---
I''m not completely clear on what your trying to accomplish but it sounds like STI may be what your looking for? http://wiki.rubyonrails.org/rails/pages/singletableinheritance Good luck! Tim On Jan 28, 3:40 pm, Duane Morin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> This might be a painfully bad idea, but it''s gotten me curious. I have > a generic object Node, which has a name attribute. Say for example that > one of the names is "Widget". > > What I''m wondering is, is there a way to manipulate ActiveRecord to make > a class named Widget, that behaves exactly like a Node with the only > difference being that all operations only work on the condition > (name="Widget") is true? I can do a simple class Widget < Node to > get it started, but I''m looking for what the next line would be, where I > can specify the global condition. In all other cases, > > History : The database itself is generated rather, well, generically by > scanning a file where I don''t know the nature of the content beyond > simple node relationships (i.e. I don''t know ahead of time all values > for "name"). However, I''m thinking that after the flat data storage > portion is taken care of I could go in and maybe write some sort of > generator for myself that would build up the Ruby classes to deal with > the database, and hide the whole thing. > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Duane Morin
2009-Jan-28 23:55 UTC
Re: Can I "fake" an object model on top of a flat ActiveReco
You know, that might be exactly it. I knew I''d heard it somewhere before :). Thanks! Sorry for the interruption. D Duane Morin wrote:> This might be a painfully bad idea, but it''s gotten me curious. I have > a generic object Node, which has a name attribute. Say for example that > one of the names is "Widget". > > What I''m wondering is, is there a way to manipulate ActiveRecord to make > a class named Widget, that behaves exactly like a Node with the only > difference being that all operations only work on the condition > (name="Widget") is true? I can do a simple class Widget < Node to > get it started, but I''m looking for what the next line would be, where I > can specify the global condition. In all other cases, > > History : The database itself is generated rather, well, generically by > scanning a file where I don''t know the nature of the content beyond > simple node relationships (i.e. I don''t know ahead of time all values > for "name"). However, I''m thinking that after the flat data storage > portion is taken care of I could go in and maybe write some sort of > generator for myself that would build up the Ruby classes to deal with > the database, and hide the whole thing.-- 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 -~----------~----~----~----~------~----~------~--~---