views:

51

answers:

1

While working with ActiveRecord I have a table which stores a serialized array of participant usernames for each row in one field. Is there an easy way to search for all rows who contain a specific user?

class Thing < ActiveRecord::Base
  serialize :participants
end

I realise I could just make a new linked table for the participants, but I feel like that would increase my overhead unnecessarily -- what do you think?

+1  A: 

You should create a new table for the participants. If the usernames are already in a separate table (which I assume they are), I'd recommend making this a has_many :through association.

Greg Campbell
Yeah, I think you're right there. I've realised I can make use of a Users table elsewhere (despite the fact that it will only hold usernames and nothing else!) mind you, I'm thinking habtm might be better, but that's a well discussed debate! Thanks very much!
JP