[Rails] Re: Model association help...

2008-09-24 Thread Frederick Cheung
On 24 Sep 2008, at 10:46, Frederick Cheung wrote: > > On 24 Sep 2008, at 00:44, ressister wrote: > >> >> Right Heimdull, thanks. So my model setup is correct for what I'm >> trying to achieve you think? Any idea why this works: >> >> @first = Entry.find(:first, :include => :category) >> @first

[Rails] Re: Model association help...

2008-09-24 Thread Frederick Cheung
On 24 Sep 2008, at 00:44, ressister wrote: > > Right Heimdull, thanks. So my model setup is correct for what I'm > trying to achieve you think? Any idea why this works: > > @first = Entry.find(:first, :include => :category) > @first.category.name > > ...and this does not? > > @entries = Entry.

[Rails] Re: Model association help...

2008-09-23 Thread ressister
Right Heimdull, thanks. So my model setup is correct for what I'm trying to achieve you think? Any idea why this works: @first = Entry.find(:first, :include => :category) @first.category.name ...and this does not? @entries = Entry.sum(:price, :include => :category, :conditions => ['user_id =

[Rails] Re: Model association help...

2008-09-23 Thread heimdull
> > > Categories doesn't have an entry_id, it doesn't seem to be picking up > > entry_category as the join table, though based on its naming, it isn't > > a traditional join table otherwise it would be called > > category_entry. > With the setup that Andres suggested you need a entry_id in the ca

[Rails] Re: Model association help...

2008-09-23 Thread Andres Rodriguez
I think it has to be with the type of relationships you set up. As I told you, you just need a one-to-many relationship reading your code. I tried your find with a many-to-many relationship and it worked for me. On Tue, Sep 23, 2008 at 4:05 PM, ressister <[EMAIL PROTECTED]> wrote: > > Hi Andres,

[Rails] Re: Model association help...

2008-09-23 Thread ressister
Hi Andres, thanks for the reply. I tried your suggested setup, but it didn't work. I then tried a simpler query with my existing model setup (which you see above) which did work... @first = Entry.find(:first, :include => :category) @first.category.name Both those work which is great. However,

[Rails] Re: Model association help...

2008-09-23 Thread Andres Rodriguez
An entry can only belong to a category right? If this is the case you don't need this many-to-many association. You just have to: class Category < ActiveRecord::Base has_many :entries end class Entry < ActiveRecord::Base belongs_to :user belongs_to :category end This will let you do: my_entr