Forum: Ruby on Rails Can I "fake" an object model on top of a flat ActiveRecord?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Duane M. (Guest)
on 2009-01-29 01:40
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.
Tim (Guest)
on 2009-01-29 01:54
(Received via mailing list)
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/singletabl...

Good luck!
Tim

On Jan 28, 3:40 pm, Duane M. <removed_email_address@domain.invalid>
Duane M. (Guest)
on 2009-01-29 01:55
You know, that might be exactly it.  I knew I'd heard it somewhere
before :).

Thanks!  Sorry for the interruption.

D
Duane M. 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.
This topic is locked and can not be replied to.