[Rails] Re: Re: Re: Modelling Foreign Keys
Arch Stanton
d6veteran at gmail.com
Mon Apr 3 16:48:54 GMT 2006
Steve Koppelman wrote:
> The point of telling Rails about the relationships between models is not
> because Rails will magically create scaffolding for you but because
> you'll be able to access you data through the relations.
>
> For instance, once you've set up those two relationships in your models,
> you can do things like
>
> @advisor = Advisor.find(1)
> @students = @advisor.students
>
> and conversely, if you have a student selected into @student, you can
> get the advisor's name simply via @student.advisor.name
>
> Or if you're updating a student's attributes in a controller action, if
> you set some of @student.advisor's attributes, the changes to the
> advisor will also get saved when you simply call @student.save
>
> and all sorts of stuff like that.
>
Thanks for the reply. I cleaned up my typos and tried calling
@test.test_type.id and it works. That is cool.
--
Posted via http://www.ruby-forum.com/.
More information about the Rails
mailing list