문제

I'm implementing a password login to a site that has only oAuth login. The User has a relation to a Facebook_account model where it stores facebook data.

I want this relationship to be dependent on value in the User model.

ie. has_one :facebook_account, if: :fb_login?

Is this possible or am I doing something wrong?

Using rails 4.0.4

Thanks

도움이 되었습니까?

해결책

Simply do

has_one :facebook_account

You don't have to assign anything to the association, rails are fine with association being nil. In fact, you don't even need this boolean field, as you can simply call user.facebook_account.present?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top