Associate field in associated table

Hello! Here’s come code:

ItemSupplier.first.item.name # returns name

I want:

ItemSupplier.first.name

Is there a more correct way than:

def name
item.name
end

Thanks a bunch,
–Peter

(Ruby 1.8.7, Rails 2.3.8)

On 6 November 2010 22:15, Peter E. [email protected] wrote:

Hello! Here’s come code:

ItemSupplier.first.item.name # returns name

I want:

ItemSupplier.first.name

To return the same name. Is it possible to do that?

Provide an instance method of ItemSupplier, called name, that returns
item.name. Don’t forget to check for item nil.

Colin

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