1
에 join_table 사용 ACESS 수, 나는 다음과 코드가 내 데이터베이스에서가 어떻게 테이블의 속성은 모델 A 앱에서
class UserProfile < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :knowledge_areas, join_table: 'user_profiles_knowledge_areas', order: 'identifier'
class KnowledgeArea < ActiveRecord::Base
attr_accessible :identifier, :label_key
attr_readonly :identifier, :label_key
을, 나는 테이블 호출 이름이 있습니다 user_profiles_knowledge_areas를
이 테이블의 레코드를 어떻게 계산하고 액세스 할 수 있습니까?
내가 좋아하는 몇 가지 옵션, 시도 :<%= @teste = UserProfile.knowledge_areas.find(:all) %>
<%= @a = UserProfile.user_profiles_knowledge_areas %>
그러나 사람이, 누군가가 나를 도울 수 주시기 바랍니다 작품?
users = User.find(:all)
for user in users do
puts user.user_profile.knowledge_areas
end
와우, 덕분에 많이, 내가 이해 : –
Np! 희망이 당신을 도왔습니다! –