I have two tables User and Order and association between those two table as follow.
in User model
has_many :orders, dependent: :destroy
in Order model
belongs_to :user
I want to select all data from order table but instead of user_id I want to select name of that user from User table.
how can I do in rails? thanks in advance.
You can simply do the following:
And then:
This is called eager loading, you can find documentation here: http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations