Astorian
2007-Jul-20 17:30 UTC
has_many_and_belongs_to_"one"? beginner question, go easy on me ....
Greetings. I am new to RoR, and to programming in general, so I
apologize if the solution is trivial.
My goal is to keep track of the 5 most common "Tag_Relationships" in a
tagging scheme. This would let me ask such things as "what tag
accompanies the tag ''computer'' most often, second most
often" etc.. I
figured this might be easier than storing an Array with the last_five
per Agile Web Development edition 2. I chose to use the acts_las_list
feature.
my question involves two models
Tag
...
has_many :tag_relationships, :order => :position
validates_uniqueness_of :name
Tag_Relationship
belongs_to :tag, :foreign_key => ''related_tag_id''
acts_as_list :scope => :tag
validates_uniqueness_of :tag_id, :scope => :related_tag_id
Questions. Something looks fishy to me in the belongs_to for
Tag_Relationships. I had to do this to get it to work, but really, the
tag_relationship belongs to the original tag, not the referred tag.
What is the correct way to use has_many / belongs_to in this case? I
would like to be able to do the following
t = Tag.find(1)
trs = t.tag_relationships
and then iterate over the collection and get the name for each
referred tag. My tag_relationships table is as follows
create_table "tag_relationships", :force => true do |t|
t.column "tag_id", :integer
t.column "related_tag_id", :integer
t.column "position", :string #ranking
for this particular tag
t.column "relationships_count", :integer, :default => 1
#number
of times this relationship has been recorded
end
Thanks in advance
John
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Jul-20 20:09 UTC
Re: has_many_and_belongs_to_"one"? beginner question, go ea
Astorian wrote:> Greetings. I am new to RoR, and to programming in general, so I > apologize if the solution is trivial. > Thanks in advance > > JohnWell, I did not use act as, but I know you can do this... t = Tag.find(1) trs = t.tag_relationships ...when you use has_many and belongs_to :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---