I like using the ActiveRecord methods instead of raw sql, so here it
goed:
I assume that you have these 3 model:
class Owner < ActiveRecord::Base
has_many :risks
end
class Risk < ActiveRecord::Base
belongs_to :owner
has_many :changes
end
class Change < ActiveRecord::Base
belongs_to :risk
end
def reportbyowner2
@owner = Owner.find(params[:owner])
@risks = @owner.risks.all(:conditions => { :status => 'Open'})
@risks.each do |risk|
risk.print_the_details
risk.changes.each{|change| change.print_the_details }
end
end
On Sep 8, 12:24 pm, 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.
>
> 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
-~----------~----~----~----~------~----~------~--~---