rails renaming associations

后端 未结 2 842
不思量自难忘°
不思量自难忘° 2021-02-18 23:22

I have two models, TreeNode and User. Each user has_one TreeNode, which is the root of the tree.

class TreeNode
  acts_as_tree
  belongs_to :user
e         


        
相关标签:
2条回答
  • 2021-02-18 23:52
    has_one :tree, :class_name => "TreeNode"
    

    Keep in mind, this assumes a foreign key called user_id in the tree_nodes table.

    Edit: If that doesn't work, you might need to specify the foreign key (:foreign_key => :user_id), but I don't think so.

    0 讨论(0)
  • 2021-02-18 23:57

    Apparently :class_name has been replaced with :source.

    0 讨论(0)
提交回复
热议问题