Problem with belongs_to

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?



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.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs