Forum: Ruby on Rails my has_many has many errors!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
633ada55ad6d9831e08a6ae23270baf4?d=identicon&s=25 mixplate (Guest)
on 2007-04-28 21:26
USER
has_many categories

CATEGORY
belongs_to user
has_many notes

NOTES
belongs_to category


this is breaking..

@userCategories = Category.find(:all, :conditions => "user_id = 1",
:include => :notes)


yes, user_id is a column in my category table....thanks!
Aaf8b976fe83ca8483c96096c8069571?d=identicon&s=25 Zach Moazeni (Guest)
on 2007-04-28 22:09
(Received via mailing list)
What is the error message given and the SQL generated (You can find
the SQL from the log)

-Zach
633ada55ad6d9831e08a6ae23270baf4?d=identicon&s=25 mixplate (Guest)
on 2007-04-28 23:51
hi Zach,
Thanks for the reply...i found my careless error.  there ww
a null value in my db that was causing the error!
361ba1bcc1d2c5a8885dd093dbb96bb6?d=identicon&s=25 Michael Kovacs (Guest)
on 2007-04-29 01:16
(Received via mailing list)
Hi there,

I'm actually wondering why you're finding the categories that belong
to a given
user in the manner that you've shown us. You've gone through all that
trouble to
define your user -> category relationship why not use it?

user = User.find(1)
@userCategories = user.categories

I see you're prefetching notes as well so you can add that to your
relationship declaration if
you really need them.

Anyway, not saying your usage isn't for good reason but given the
context it sorta jumps out
at me that you're not using the association for what's essentially
the same exact query as you're building by hand.

Best regards,

-Michael
http://javathehutt.blogspot.com
This topic is locked and can not be replied to.