Ruby on Rails Sunday, September 5, 2010

On 5 September 2010 00:31, Tom Fielding <tomfieldingpersonal@gmail.com> wrote:
> Hello,
> Sorry if this is a noob question.
> I'm trying to store a hash of values (a user's music collection) into a
> single database record without having to have a separate row in the db for
> each music track the user has in his collection.
> e.g. User 9
> { 12319 => "Artist X: Song Name 1",
>   12198 => "Artist X: Song Name 2",
>   19180 => "Artist Y: Song Name 3",
>   92810 => "Artist Z: Song Name 4" }

Not answering the question, I know, but I would advise against doing
it this way. Have a tracks table, User has_many tracks, Track
belongs_to user. Then for a user his tracks are
current_user.tracks
and for each track the artist and name are track.artist and track.name.
You will not have to write all the code you are struggling with, Rails
will do it for you. The less code you have to write the better.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment