I''m sure this exists somewhere but I cant figure out where I should be looking after looking through the apis. If I have a something like class TodoItem < ActiveRecord::Base belongs_to :assigned_to, { :foreign_key => ''admin_user_id'', :class_name => ''AdminUser'' } end and in a class method i have the symbol :assigned_to how do i get information from it... so it would work effectively like assigned_to.name the class method in question is included in the TodoItem ( or any other class for that matter ) as a mixin... _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
The Rails API page on ActiveRecord associations is here: http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html Basically, if you have an object called @todo, that belongs to @list you could reference it as: @todo.list # this is like calling List.find(list_id) Tom On 7/7/05, Sean T Allen <sean-5W9FBhQXBOtBDgjK7y7TUQ@public.gmane.org> wrote:> I''m sure this exists somewhere but I cant figure out where I should be > looking after looking through the apis. > > If I have a something like > > class TodoItem < ActiveRecord::Base > belongs_to :assigned_to, { :foreign_key => ''admin_user_id'', > :class_name => ''AdminUser'' } > end > > and in a class method i have the symbol :assigned_to > > how do i get information from it... > > so it would work effectively like assigned_to.name > > the class method in question is included in the TodoItem ( or any other > class for that matter ) > as a mixin... > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >
I understand that... I don''t have an object... its in a class method i want to be able to check out an association ( i have the symbol ) and call cget the table name and other inspect the association without having an object to be more clear: i have a class that is adding functionality ( as a mixin ) to models sometimes i need information on associated classes... make sense? Tom Davies wrote:>The Rails API page on ActiveRecord associations is here: > >http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html > >Basically, if you have an object called @todo, that belongs to @list >you could reference it as: > >@todo.list # this is like calling List.find(list_id) > >Tom > >On 7/7/05, Sean T Allen <sean-5W9FBhQXBOtBDgjK7y7TUQ@public.gmane.org> wrote: > > >>I''m sure this exists somewhere but I cant figure out where I should be >>looking after looking through the apis. >> >>If I have a something like >> >>class TodoItem < ActiveRecord::Base >> belongs_to :assigned_to, { :foreign_key => ''admin_user_id'', >>:class_name => ''AdminUser'' } >>end >> >>and in a class method i have the symbol :assigned_to >> >>how do i get information from it... >> >>so it would work effectively like assigned_to.name >> >>the class method in question is included in the TodoItem ( or any other >>class for that matter ) >>as a mixin... >> >> >> >> >>_______________________________________________ >>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 > > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Thursday 07 July 2005 21:37, Sean T Allen wrote:> i have a class that is adding functionality ( as a mixin ) to models > sometimes i need information on associated classes...reflect_on_association? Michael -- Michael Schuerig Life is just as deadly mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org As it looks http://www.schuerig.de/michael/ --Richard Thompson, Sibella
Michael Schuerig wrote:>On Thursday 07 July 2005 21:37, Sean T Allen wrote: > > > >>i have a class that is adding functionality ( as a mixin ) to models >>sometimes i need information on associated classes... >> >> > >reflect_on_association? > >Michael > > >Beautiful thanks. Dont know how I missed that. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails