Say I have the following association with an attached condition:

    belongs_to :admin_user,
        :class_name => 'User',
        :foreign_key => :admin_user_id,
        :conditions=> 'users.admin=TRUE' # or any variation with hash or
array, {:admin => true}, etc.

The API 
states<http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M001835>that
the :conditions option on belongs_to will:

Specify the conditions that the associated object must meet in order to be
> included as a WHERE SQL fragment, such as authorized = 1.
>

But the output shows no WHERE clause on the select, and in any case I would
expect that conditions like this on a belongs_to would prevent persisting
that relationship to begin with, on the INSERT not the SELECT. This option
seems to have no effect on a belongs_to association, unless I'm missing
something. The option makes sense on a has_many, I just don't see how it
applies to belongs_to.

I've posted this on
stackoverflow<http://stackoverflow.com/questions/2156514/what-is-the-purpose-of-conditions-on-a-belongs-to-association>as
well, just fyi.

Thanks,
Dave

-- 
And all the Knave e’er wanted was his rug
As spoken of, which tied the room together.

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to