Topic: ActiveRecord Question

Here is how I am currently solving my problem:

      @purchased_items = Customer.find_by_email(params[:email]).purchased_items

      for item in @purchased_items
        item["store_entry"] = StoreEntry.find(item.store_entry_id)

Basically, for every purchased item, I'd like to be able to access the actual item.  So each PurchasedItem has a field called store_entry_id, and I'd like to be able to get the entry from StoreEntry using that ID.

Is there a way to specify this in the model?

I tried putting has_one :store_entry in PurchasedItem but it looks for a PurchasedItem in StoreEntry.

Last edited by alanzo (2007-03-17 21:29:34)

Re: ActiveRecord Question

Use "belongs_to :store_entry" in the PurchasedItem model, not has_one. Then you can "item.store_entry".

Railscasts - Free Ruby on Rails Screencasts

Re: ActiveRecord Question

That worked.  Thank you!