Hi Shelby,
You may want to read more detail about associations on this page:
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
Your associations seem ok to me (at a quick glance). The way you
would access your pieces from a repertoire_list called @rlist is
@rlist.repertoire_list_pieces.
For the other direction, if you have a piece called @piece you would
access its list by saying @piece.repertoire_list.
Hope that helps.
Tom
On 7/16/05, Shelby Westman
<shelby.westman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I am confused about the proper way to load up a joined table.
>
> I have two tables (and models) that have a many to one relationship.
>
> class RepertoireList < ActiveRecord::Base
> has_many :repertoire_list_pieces
> end
>
> class RepertoireListPiece < ActiveRecord::Base
> belongs_to :repertoire_list
> end
>
> When I do this statement in my controller, then it loads the
> RepertoireList class, but apparently not the RepertoireListPieces
>
> (from controller)
> def update_replist_modify
> @repertoire_list =
RepertoireList.find(params[''id''])
> end
>
> A RepertoireLIst has many pieces. Where do I load them? Is my schema
> wrong, or missing a field in the repertoire_lists table?
>
> Thanks!
> Shelby
>
> Schema:
>
> create table repertoire_lists (
> id int not null
auto_increment,
> name varchar(150) not null,
> levels_type varchar(30),
> primary key (id)
> );
>
>
> create table repertoire_list_pieces (
> id int
not null auto_increment,
> composer varchar(100) not null,
> title varchar(100) not
null,
> duration int
not null,
> level varchar(50) not
null,
> repertoire_list_id int not
null,
> constraint fk_pieces_repertoire_list foreign key
> (repertoire_list_id) references repertoire_lists(id),
> primary key (id)
> );
>
> Models:
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>