Issue in alias model name in rails -


i have 2 models user , dtype. in users table have 2 column named dtype_id , dtype_second contains id's of dtype. need both columns values through association.

using @user.dtype.name give me value of first column (dtype_id).

now, need value of second column i.e dtype_second.

for i'm trying this:

in user model: belongs_to :dtype  in dtype model: has_many :users has_many :dtype_seconds, :foreign_key => 'dtype_second', :class_name => "user"  on view: <%= @user.dtype_seconds.name %> 

the issue i'm not getting value or error.

your adding has many dtype, you're trying call method on user. have define dtype_second association on user:

class user < activerecord::base   belongs_to :dtype   belongs_to :dtype_alternative, :foreign_key => 'dtype_second', :class_name => "dtype"    ... end  <%= @user.dtype_alternative.name %> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -