나는이 user_profile
has_one 협회 선택 특정 필드
와 has_one
협회와 내가 user_profile로 대신 user_profile
의에서 이름 필드를 선택합니다 user
모델. *
,
user = User.first
user.user_profile.select(:name)
하지만 이건 작동하지 않습니다.
나는이 user_profile
has_one 협회 선택 특정 필드
와 has_one
협회와 내가 user_profile로 대신 user_profile
의에서 이름 필드를 선택합니다 user
모델. *
,
user = User.first
user.user_profile.select(:name)
하지만 이건 작동하지 않습니다.
업데이트 : 것 같다
, 즉 다른 방향과 다르게 일대일 연결을 처리 레일. 당신은 두 가지 옵션이 있습니다
1) 협회에서 선택한 속성 정의를 항상 선택합니다 그
has_one :user_profile, :select => [:name, :id]
2)처럼, select
를 추가 할 수 있습니다 모델의 특정 찾기를 정의 이 :
def my_profile
UserProfile.find(self.user_profile_id)
end
....
my_profile.select(:name)
ORIGINAL :
has_many
방향의 경우, 작동 :
내가 좋아하는, 내 코드에서 방법을 시도했다 :
= User.find("admin").article.select(:title).to_sql
그것은 올바른 SQL 반환
SELECT title
FROM "articles"
WHERE "articles"."user_id" = 1364
나는 레일 3.2을 사용하고를 .5 – shajin