Activerecord - finding parent info

i am SURE this is really simple… and i am SURE i have read this a
million times… but i am not wiring this up in my brain correctly…

if i have a parent class that has fields:

Podcasts
id
title
description

and a child class like:

Episodes
id
podcast_id
title
description
filename

i can get the episode information all day… but using the “Episode”
class, can i access the “Podcast” class info?

for instance… if i said:

@episode = Episodes.find(1)

and got the episode with id=1, can i also get the podcast info that is
referenced in with Podcast.find(@episode.podcast_id)

is there a one liner that would give me the data?

am i making sense?

thanks!

On 5-Jul-06, at 1:28 PM, sergio ruiz wrote:

is there a one liner that would give me the data?

Assuming your models are wired up like so:

class Podcast < ActiveRecord::Base
has_many :episodes
end

class Episode < ActiveRecord::Base
belongs_to :podcast
end

You’d be able to do this:

e = Episode.find(1)
e.podcast

/Jeff

Assuming your models are wired up like so:

class Podcast < ActiveRecord::Base
has_many :episodes
end

class Episode < ActiveRecord::Base
belongs_to :podcast
end

You’d be able to do this:

e = Episode.find(1)
e.podcast

yes, that is how they are wired… i will try that…

thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs