On Sep 8, 11:24 am, Martyn Elmy-liddiard <[EMAIL PROTECTED]
s.net> wrote:
> Shiv N Gautam wrote:
> > On Fri, Sep 5, 2008 at 8:47 PM, Martyn Elmy-liddiard <
> > [EMAIL PROTECTED]> wrote:
>
> >> @changes = Change.find_by_sql(["SELECT * FROM changes c where c.risk_id
> >> = ? order by c.id", @risks.id])
>
> >  How many records are there in the @risks object. You're doing
> > c.risk_id=@
> > risks.id, so if there are multiple rows in @risks then the query wont
> > return
> > any result.
>
> >> end
>
> >> Any help please.
>
> >> Many thanks.
> >> --
> >> Posted viahttp://www.ruby-forum.com/.
>
> Shiv,
>
> The @risks object will have multiple risks. What I am trying to do is
> for each risk I select I print the risk details then go and get any
> changes records associted with that risk record and print them then go
> round again for the next risk.
>
> Can you advise the syntax I would need to use to achieve this.

I wouldn't use find_by_sql at all.

owner = Owner.find params[:owner]
Changes.find_all_by_risk_id owner.open_risks

as long as owner has an open risks association like so

has_many :open_risks, :conditions => {:status => 'Open'}, :class_name
=> 'Risk'}

You could also do this with a named_scope.

Fred

>
> Much appreciated
>
> Martyn
>
>
>
> > ~~
> > Shiv N Gautam
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to