With AR, here was I thinking I could set up a table called "Accessors", which has an attribute "label". Then another table called "Users", which has "username" and "password" attributes. what I wanted to do was have this: class Accessor < ActiveRecord::Base end class User < Accessor end So I was thinking... cool then when you click "new" on user, you get a new record in both tables, with data filled in for both (ie we get the label into the accessors table, and the username and password into the users table, and all I have to do is do a foreign key "accessor_id" in the users table. It doesn''t work like this! I don''t paritcularly want to access my User object''s "label" attribute by proxying through its "related" (what should be inherited from instead) Accessor object. Is there some way that we can do this easily? Julian _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 10/3/05, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> > > With AR, here was I thinking I could set up a table called "Accessors", > which has an attribute "label". Then another table called "Users", which has > "username" and "password" attributes. > > > > > what I wanted to do was have this: > > > > > class Accessor < ActiveRecord::Base > > end > > class User < Accessor > > end > > > > > So I was thinking... cool then when you click "new" on user, you get a new > record in both tables, with data filled in for both (ie we get the label > into the accessors table, and the username and password into the users > table, and all I have to do is do a foreign key "accessor_id" in the users > table. > > > > > It doesn''t work like this! > > > > > I don''t paritcularly want to access my User object''s "label" attribute by > proxying through its "related" (what should be inherited from instead) > Accessor object. > > > > > Is there some way that we can do this easily? > > > > > JulianRead up on AR Single Table Inheritance: http://rails.rubyonrails.com/classes/ActiveRecord/Base.html In your example, you''d put all 3 columns in the accessors table and not have a users table. I know it''s not exactly the best solution for SQL purists, but it is simple and it works. -- rick http://techno-weenie.net
On 04/10/2005, at 2:56 PM, Rick Olson wrote:> On 10/3/05, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > >> > > Read up on AR Single Table Inheritance: > http://rails.rubyonrails.com/classes/ActiveRecord/Base.html > > In your example, you''d put all 3 columns in the accessors table and > not have a users table. I know it''s not exactly the best solution for > SQL purists, but it is simple and it works. > > --Yes. I know about STI, thanks. My question wasn''t about it. I didn''t really want to use it. Bleh! :-) Don''t you think it''d be more beautiful (from a rails point of view even) to have it done the way I explained? Julian.
On Oct 4, 2005, at 10:50 AM, Julian Leviston wrote:> > On 04/10/2005, at 2:56 PM, Rick Olson wrote: > >> On 10/3/05, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: >> >>> >> >> Read up on AR Single Table Inheritance: >> http://rails.rubyonrails.com/classes/ActiveRecord/Base.html >> >> In your example, you''d put all 3 columns in the accessors table and >> not have a users table. I know it''s not exactly the best solution for >> SQL purists, but it is simple and it works. >> >> -- > > > Yes. I know about STI, thanks. My question wasn''t about it. I didn''t > really want to use it. Bleh! :-) > > Don''t you think it''d be more beautiful (from a rails point of view > even) to have it done the way I explained? > > Julian.Have you read John''s post [1] and Jeremy''s comment on it? Should be helpful to you. [1] http://johnwilger.com/articles/2005/09/29/class-table-inheritance-in- rails-with-postgresql -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com http://rubyi.st
> Yes. I know about STI, thanks. My question wasn''t about it. I didn''t > really want to use it. Bleh! :-) > > Don''t you think it''d be more beautiful (from a rails point of view > even) to have it done the way I explained? > > Julian. >Sure, that''s why I use postgresql :) The nice thing is, rails thinks nothing is out of the ordinary. http://www.postgresql.org/docs/current/static/ddl-inherit.html -- rick http://techno-weenie.net
Man that is just beautiful. (pg inheritance) But Id be really interested if there was a way to inherent from a parent AR model. Sam On 10/4/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Yes. I know about STI, thanks. My question wasn''t about it. I didn''t > > really want to use it. Bleh! :-) > > > > Don''t you think it''d be more beautiful (from a rails point of view > > even) to have it done the way I explained? > > > > Julian. > > > > Sure, that''s why I use postgresql :) > > The nice thing is, rails thinks nothing is out of the ordinary. > > http://www.postgresql.org/docs/current/static/ddl-inherit.html > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
And today I find that relationships aren''t inherited either. <sigh> It''s fine that they aren''t, but shoudln''t it be possible to make it so they ARE? (with a relationships :inherited macros or something? Is there any potential future relief from this? or is this "the opinion", and I should "put up or create something else"? Julian On 05/10/2005, at 12:59 AM, Scott Barron wrote:> > On Oct 4, 2005, at 10:50 AM, Julian Leviston wrote: > > >> >> On 04/10/2005, at 2:56 PM, Rick Olson wrote: >> >> >>> On 10/3/05, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: >>> >>> >>>> >>>> >>> >>> Read up on AR Single Table Inheritance: >>> http://rails.rubyonrails.com/classes/ActiveRecord/Base.html >>> >>> In your example, you''d put all 3 columns in the accessors table and >>> not have a users table. I know it''s not exactly the best >>> solution for >>> SQL purists, but it is simple and it works. >>> >>> -- >>> >> >> >> Yes. I know about STI, thanks. My question wasn''t about it. I >> didn''t really want to use it. Bleh! :-) >> >> Don''t you think it''d be more beautiful (from a rails point of view >> even) to have it done the way I explained? >> >> Julian. >> > > Have you read John''s post [1] and Jeremy''s comment on it? Should > be helpful to you. > > [1] http://johnwilger.com/articles/2005/09/29/class-table- > inheritance-in-rails-with-postgresql > > -- > Scott Barron > Lunchbox Software > http://lunchboxsoftware.com > http://lunchroom.lunchboxsoftware.com > http://rubyi.st > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
okay I think you totally rock and I''m gonna have to have your children. actually I already knew you rocked coz you''ve helped me before. [hugs] thanks man. Jules. On 05/10/2005, at 1:33 AM, Rick Olson wrote:>> Yes. I know about STI, thanks. My question wasn''t about it. I didn''t >> really want to use it. Bleh! :-) >> >> Don''t you think it''d be more beautiful (from a rails point of view >> even) to have it done the way I explained? >> >> Julian. >> >> > > Sure, that''s why I use postgresql :) > > The nice thing is, rails thinks nothing is out of the ordinary. > > http://www.postgresql.org/docs/current/static/ddl-inherit.html > > -- > rick > http://techno-weenie.net >
will it inherit relationships at a db level too? On 05/10/2005, at 1:33 AM, Rick Olson wrote:>> Yes. I know about STI, thanks. My question wasn''t about it. I didn''t >> really want to use it. Bleh! :-) >> >> Don''t you think it''d be more beautiful (from a rails point of view >> even) to have it done the way I explained? >> >> Julian. >> >> > > Sure, that''s why I use postgresql :) > > The nice thing is, rails thinks nothing is out of the ordinary. > > http://www.postgresql.org/docs/current/static/ddl-inherit.html > > -- > rick > http://techno-weenie.net >