Problem with belongs_to


#1

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


#2

Actually, it seems I was kind of rubber ducking here :slight_smile: I found out the
answer just after I sent the mail. It should of course be has_one
instead of belongs_to.

/Marcus