mysql - Rails 4 access table attributes from has_one association -


i have 2 models user , account

class user < activerecord::base   has_one :account end   class account < activerecord::base       belongs_to :user     end 

in users controller retrieving users

@user = user.list('', false,'company', 'asc') 

where "list" method described in model retrieve records

in users table have 2 columns "id" , "company_name" , in account table have columns "user_id" , "country"

now want array @user retrieve company name , country can found user_id in accounts table

please tell me how can thankx in advance

how about:

# app/models/user.rb class user < activerecord::base   has_one :account    scope :with_account_info, -> { includes(:account) }   default_scope{with_account_info} end 

the final 2 lines merged 1 if prefer that, i.e.:

default_scope{ includes(:account) }  

hth


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -