Hi list, I need to represent a relationship between three tables: Tags (id, name) Users (id, name, email, ... ) Documents (id, title, ... ) I created a forth table called Assignments(id, tag-id, user-id, document-id, date). I have couple of questions: Should I use belongs-to and has-many to capture this? If so, How can I do that? should I have the id as the primary key in Assignment table or not? Any help is most appreciated. Thanks, -Vanesa -- Posted via http://www.ruby-forum.com/.
If you are attempting to implement tagging functionality on your documents then you should try to use acts_as_taggable gem or acts_as_taggable plugin. (I used gem in my use case, because it was more mature). Chances are that you want to users to be able to tag documents? if thats the case then using acts_as_taggable gem will make your life easy. get back to me, if that is the case I can guide you further. Anu ----- Original Message ---- From: vanesam <vanesam@ece.ubc.ca> To: rails@lists.rubyonrails.org Sent: Saturday, April 1, 2006 1:29:53 AM Subject: [Rails] Triple relationship Hi list, I need to represent a relationship between three tables: Tags (id, name) Users (id, name, email, ... ) Documents (id, title, ... ) I created a forth table called Assignments(id, tag-id, user-id, document-id, date). I have couple of questions: Should I use belongs-to and has-many to capture this? If so, How can I do that? should I have the id as the primary key in Assignment table or not? Any help is most appreciated. Thanks, -Vanesa -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060401/446289e1/attachment.html
On Sat, Apr 01, 2006 at 11:29:53AM +0200, vanesam wrote: } Hi list, } } I need to represent a relationship between three tables: } } Tags (id, name) } Users (id, name, email, ... ) } Documents (id, title, ... ) } } I created a forth table called Assignments(id, tag-id, user-id, } document-id, date). } I have couple of questions: } Should I use belongs-to and has-many to capture this? If so, How can I } do that? } should I have the id as the primary key in Assignment table or not? Tags has_many Assignments Users has_many Assignments Documents has_many Assignments Assignments belongs_to Tag, User, Document Someone mentioned acts_as_taggable, which only really makes sense if a single Assignment (or other model) has zero or more tags, rather than the single tag you seem to be indicating. } Any help is most appreciated. } Thanks, } -Vanesa --Greg
Hi, I want the user to be able to tag the documents that exist in the system...also I like the system (the database) to keep track of "who tagged what with which tag and when". I am new to both Ruby and Rails and don''t have that much experince any help is appreciated. Thanks, -Vanesa unknown wrote:> If you are attempting to implement tagging functionality on your > documents then you should try to use acts_as_taggable gem or > acts_as_taggable plugin. (I used gem in my use case, because it was more > mature). > > Chances are that you want to users to be able to tag documents? if thats > the case then using acts_as_taggable gem will make your life easy. get > back to me, if that is the case I can guide you further. > > Anu > > ----- Original Message ---- > From: vanesam <vanesam@ece.ubc.ca> > To: rails@lists.rubyonrails.org > Sent: Saturday, April 1, 2006 1:29:53 AM > Subject: [Rails] Triple relationship > > Hi list, > > I need to represent a relationship between three tables: > > Tags (id, name) > Users (id, name, email, ... ) > Documents (id, title, ... ) > > I created a forth table called Assignments(id, tag-id, user-id, > document-id, date). > I have couple of questions: > Should I use belongs-to and has-many to capture this? If so, How can I > do that? > should I have the id as the primary key in Assignment table or not? > > Any help is most appreciated. > > Thanks, > -Vanesa-- Posted via http://www.ruby-forum.com/.
El s?b, 01-04-2006 a las 21:41 +0200, vanesa mirzaee escribi?:> Hi, > > I want the user to be able to tag the documents that exist in the > system...also I like the system (the database) to keep track of "who > tagged what with which tag and when". > I am new to both Ruby and Rails and don''t have that much experince any > help is appreciated.Hi Vanesa, You can use UserStamp Plugin http://www.delynnberry.com/pages/userstamp/ Copy&Paste from userstamp description: "The Userstamp Plugin extends ActiveRecord::Base to add automatic updating of created_by and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created_(at/on) and updated_(at/on) attributes." Cheers! Juanjo> > Thanks, > -Vanesa > > unknown wrote: > > If you are attempting to implement tagging functionality on your > > documents then you should try to use acts_as_taggable gem or > > acts_as_taggable plugin. (I used gem in my use case, because it was more > > mature). > > > > Chances are that you want to users to be able to tag documents? if thats > > the case then using acts_as_taggable gem will make your life easy. get > > back to me, if that is the case I can guide you further. > > > > Anu > > > > ----- Original Message ---- > > From: vanesam <vanesam@ece.ubc.ca> > > To: rails@lists.rubyonrails.org > > Sent: Saturday, April 1, 2006 1:29:53 AM > > Subject: [Rails] Triple relationship > > > > Hi list, > > > > I need to represent a relationship between three tables: > > > > Tags (id, name) > > Users (id, name, email, ... ) > > Documents (id, title, ... ) > > > > I created a forth table called Assignments(id, tag-id, user-id, > > document-id, date). > > I have couple of questions: > > Should I use belongs-to and has-many to capture this? If so, How can I > > do that? > > should I have the id as the primary key in Assignment table or not? > > > > Any help is most appreciated. > > > > Thanks, > > -Vanesa >
vanesa mirzaee wrote:> Hi, > > I want the user to be able to tag the documents that exist in the > system...also I like the system (the database) to keep track of "who > tagged what with which tag and when". > I am new to both Ruby and Rails and don''t have that much experince any > help is appreciated. >It seems to me you want a habtm relationship between documents and tags. In your joining table you should store doc_id, tag_id and user_id. And as you are building your tags ensure to properly set the user_id attribute (check the rails api for has_and_belongs_to_many to find out how this is done) Then you can get all tags from your document by saying document.tags, or all documents that are tagged with something like by saying tag.documents and lastly, to get all user.tags just add a tags method in your users model like this: def tags Tag.find_by_sql(["SELECT * FROM tags, documents_tags WHERE documents_tags.user_id = ? AND tags.id = documents_tags.tag_id"], self.id) end -- Bryan Buecking> Thanks, > -Vanesa > > unknown wrote: > >> If you are attempting to implement tagging functionality on your >> documents then you should try to use acts_as_taggable gem or >> acts_as_taggable plugin. (I used gem in my use case, because it was more >> mature). >> >> Chances are that you want to users to be able to tag documents? if thats >> the case then using acts_as_taggable gem will make your life easy. get >> back to me, if that is the case I can guide you further. >> >> Anu >> >> ----- Original Message ---- >> From: vanesam <vanesam@ece.ubc.ca> >> To: rails@lists.rubyonrails.org >> Sent: Saturday, April 1, 2006 1:29:53 AM >> Subject: [Rails] Triple relationship >> >> Hi list, >> >> I need to represent a relationship between three tables: >> >> Tags (id, name) >> Users (id, name, email, ... ) >> Documents (id, title, ... ) >> >> I created a forth table called Assignments(id, tag-id, user-id, >> document-id, date). >> I have couple of questions: >> Should I use belongs-to and has-many to capture this? If so, How can I >> do that? >> should I have the id as the primary key in Assignment table or not? >> >> Any help is most appreciated. >> >> Thanks, >> -Vanesa >> > > >