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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -