Ruby on Rails Wednesday, November 26, 2014

Hi All,

I have an issue on filtering a has_many through association. My model is as follows

class Group 
   has_and_belongs_to_many :messages
   has_many :tags, through :messages
end

class Message
   has_and_belongs_to_many :tags
end

class Tag
  has_and_belongs_to_many :messages
end

This gives me the tags for all messages in a group. Groups.first.tags . However I want to filter on an attribute in messages (Message.where(:created => '11-11-2014')) based on which tags should be retrieved. Is it possible to do this in a has_many though association? Thanks in advance

Thanks,
Ganesh

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CALFmRoE96wMtKOkxkE7vx%2B7BhduN0kxRvBt08VD3r_a7-NiWBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment