That works, but here's a few hints.   Generally, you specify the
"where" clause in ":conditions", the select clause in ":select", inner
joins in ":joins" and outer joins in ":include".   (If it doesn't
matter whether it's inner or outer, use :include, giving Rails more
flexibility to rearrange the query).   'from' is deduced
automatically.  It's very rare that you'd need to specify the select,
and Rails has a standard way of doing renaming
(seehttp://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
: table aliasing) .   The next thing we notice is that your where
clause is redundant -- your inner join is doing all the work.   You
can't add a :joins condition to the belongs_to, but you can add it to
the corresponding has_many:

has_many :classifications, :joins => :recognition_types

Should be all you need.

cheers,
Bryan


On Sun, Dec 11, 2011 at 11:12 AM, Drammy <[email protected]> wrote:
> I got it working on the belongs_to relationship with...
>
> belongs_to :classification_value, :conditions => 'classification_id IN
> (
>                                                        SELECT                 
>    c.id
>                                                        FROM                   
>            classifications c
>                                                                INNER JOIN     
>  recognition_types rt ON c.id = rt.classification_id
>                                                        WHERE         rt.id = 
> #{self.recognition_type_id}
>              )'
>
>
> On Dec 8, 3:02 pm, Bryan Larsen <[email protected]> wrote:
>> This is the right place.   Matt & Kevin must be busy, we haven't heard
>> from them for a while.  They're probably our two most dependable
>> question answerers.
>>
>> There are a couple of options for you.
>>
>> 1) set the options attribute on your select-one
>> (http://cookbook.hobocentral.net/api_tag_defs/select-one).   You'll
>> probably have to read the first part of the DRYML guide first to
>> understand your many options on you to customize the field.   If you
>> get stuck, yell again.
>>
>> 2) use the :conditions option on your belong_to.   This is probably
>> the easier option, but it might require learning a little about SQL
>> and/or Rails.   In other words, what I'm saying is that learning how
>> to do #1 will probably do you more good going forward.
>>
>> cheers,
>> Bryan
>>
>>
>>
>>
>>
>>
>>
>> On Thu, Dec 8, 2011 at 9:05 AM, Drammy <[email protected]> wrote:
>> > Am I asking this question in the wrong place?  Should I be asking this
>> > in the hobo cookbook?
>>
>> > Any help appreciated.  even if its RTFM at page...
>>
>> > On Dec 5, 12:35 pm, Drammy <[email protected]> wrote:
>> >> Hi all,
>>
>> >> Still pretty new to all this so apologies if this is straight forward;
>> >> I have searched for solutions as it seems quite an easy problem to
>> >> solve but alas, no joy.
>>
>> >> I have a few models like so...
>>
>> >> Classification -> ClassificationValue...  (where Classification
>> >> has_many ClassificationValues and ClassificationValue belongs_to
>> >> Classification)
>> >> RecognitionType -> Recognition... (where RecognitionType has_many
>> >> Recognitions and Recognition belongs_to RecognitionType)
>>
>> >> Fairly straight forward...  There is also another couple of
>> >> relationships...
>>
>> >> Classification -> RecognitionType  (where RecognitionType belongs_to a
>> >> Classification)
>>
>> >> ClassificationValue -> Recognition  (where Recognition belongs_to a
>> >> ClassificationValue)
>>
>> >> It is the ClassificationValue dropdown box that appears on the
>> >> Recognition edit page that is causing me grief.
>>
>> >> I want this dropdown box to only have valid values (not all
>> >> ClassificationValues).  By valid values I mean CalssificationValues
>> >> that belong_to the Classification that belongs_to the Recognition's
>> >> RecognitionType...
>>
>> >> Any ideas? (hope you followed that!)
>>
>> >> Cheers,
>> >> Drammy
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Hobo Users" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to 
>> > [email protected].
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/hobousers?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Hobo Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/hobousers?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to