Forum: Ruby on Rails Problem with belongs_to

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
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


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

Any ideas?


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.

This topic is locked and can not be replied to.