Forum: Ruby on Rails Problem with belongs_to

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.
3a6666f57152610f172a77c8fe6a7420?d=identicon&s=25 marcus (Guest)
on 2006-01-10 13:55
(Received via mailing list)
I have a model where I have a tree of nodes in one table (acts_as_tree)
where I also use a type column to get inheritance. In this table I also
have a data_id column that refers to another row in another table (the
subclass knows what table).

I also have another class that have this line

class Page < ActiveRecord::Base
   belongs_to :node,
              :foreign_key => "data_id",
              :conditions => "type == 'PageNode'"
   ...

It's supposed to refer back to the Node class so I can get to the node
from a Page instance using

@page.node.what_ever

The problem now is that @page.node == nil. I have checked the tables and
the data is correct (it must be since navigation from node to page works
perfectly)

Any ideas?

Thanks

/Marcus
3a6666f57152610f172a77c8fe6a7420?d=identicon&s=25 marcus (Guest)
on 2006-01-10 17:26
(Received via mailing list)
Actually, it seems I was kind of rubber ducking here :) I found out the
answer just after I sent the mail. It should of course be has_one
instead of belongs_to.

/Marcus
This topic is locked and can not be replied to.