sql - Find records through two intermediate models in rails? -


I have some problems, which are trying to bring some models through SQL through Rails and I am thinking Had to know a good solution originally for this particular problem, how these my classes look like:

  class members list & lt; ActiveRecord :: Base has has_many: unsubscribed class membership & lt; ActiveRecord :: Base is has_many: message is_to: subscription_list end class declaration & lt; ActiveRecord :: Base has_many: message and class message & lt; ActiveRecord :: Base is_to: subscription is_to: announcement end  

Now, I want to use all announcements for a subscription except for a duplicate. Is this possible? Can it be done with a single SQL query or is it just the willful thinking?

For example, what do I need:

  class membership list & lt; ActiveRecord :: Base Def announcements announcements.James (: Message) Where (message: {subscription: {subscription_list: self}}) End End  

me It seems that your opinion is right in general. Try this type of

  announcements (message: {subscription :: subscription_list}) where (subscription_lists: {id: self.id}) # Unlike membership list. (Subscription: {Message: announcement}). Where (announcements: {id: self.id})  

Note: * These queries can return duplicates - therefore uniq can be added * Self can be left (I have written that this is an example ID and written to avoid misunderstanding)


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -