User model :
Class User < ActiveRecord::Base
  has_many :planning_entries
PlanningEntry model :
Class PlanningEntry < ActiveRecord::Base
  belongs_to :planning
  belongs_to :user
  has_many :plannings
Planning model
Class Planning < ActiveRecord::Base
  has_many :planning_entries
- The planning table has a field day:date
- The PlanningEntry has a field state: [:approved, :canceled, etc.]
I would like to make a scope to retrieve all users not assigned to the current day's Planning using the day field.
This mean that i can't exclude users having planning_entries from old plannings
On other thing, there are several states for the PlanningEntry table and only the :approved state is considered as a true association for a user to a planning in this request
So far i did this query :
 User.joins( planning_entries: :planning ).
    where( "(plannings.day = ? AND planning_entries.state != 'approved')",
    Planning.current_day)
I tried to add some more OR / AND condition in the query to deal with all the cases needed but nothing worked so far.
Any help would be grandly appreciated
 
     
    