Rails 3.2.11

My app has a model called Plan, which has has_many self-referential
association just like
http://railscasts.com/episodes/163-self-referential-association

    has_many :matches
    has_many :counterparts, :through => :matches
    has_many :inverse_matches, :class_name => "Match", :foreign_key =>
:counterpart_id
    has_many :inverse_counterparts, :through => :inverse_matches,
:source => :plan


and in the plans_controller, I would like to find a plan (counterpart)
having many conditions.

        plans = Plan.arel_table
        @counterpart = Plan.where(
                                           ....
                                      ).where(
                                          
plans[:user_id].not_eq(current_user.id)
# eliminate current user
                                      )

in addition to this, I need one more condition. That is

A Plan (counterpart) which has yet been found by any plans.  It should
look like

      counterpart.matches.length == 0

How can I add this condition to the where clauses describe above?

thanks!

soichi

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to