rais belong_to which class to choose

Posted by Small Wolf on Stack Overflow See other posts from Stack Overflow or by Small Wolf
Published on 2010-06-02T09:25:35Z Indexed on 2010/06/02 9:33 UTC
Read the original article Hit count: 181

There is a model relation like this.

class A
belongs_to :ref_config,:class_name => 'User'
end

My question is : the A has a attribute named flag, now i want to create a function like this:

if flag == 1, I want the class A like this belongs_to :ref_config,:class_name => 'Department and if flag == 2, i want the class A like this belongs_to :ref_config,:class_name => 'User'

How can I implement the function

Thank you!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about object-relational-mapping