Monday, August 22, 2011

[Rails] multiple foreign keys in one table reference the same table column

Here is my table structure:

keyterms: id, key_word, primary key (id)
user_keywords: id, user_id, expertise_keyterm_id, partners_keyterm_id,
primary key(id), foreign key(expertise_keyterm_id), foreign
key(partners_keyterm_id)

In UserKeyword model:
class UserKeyword < ActiveRecord::Base
belongs_to :users, :class_name=>'User', :foreign_key => :user_id
belongs_to :keyterms, :class_name=> "Keyterm", :foreign_key =>
:expertise_keyterm_id
belongs_to :keyterms_expertise, :class_name=> "Keyterm", :foreign_key
=> :expertise_keyterm_id
end

In Keyterm model:
class Keyterm < ActiveRecord::Base
has_many :user_keywords, :class_name => 'UserKeyword'
end

In users controller
def myfunction
@user = User.find(params[:id])
render :xml =>@user.to_xml(:include=>{ :user_keywords=>{:include=>
:keyterms}})
end

But on the xml page, only expertise_keyterm shows up, parterner keyterm
doesn't and I am using rails 3.0.9. Could anyone help me?
Thanks,

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate