mercredi 16 novembre 2016

Sorting by another related model attributes - Ruby on Rails

I have two models related with each other as below

class Weed < ApplicationRecord
  has_many :user_transactions,:dependent => :destroy
end

This weed model has an attribute name county

and related model:

class UserTransaction < ApplicationRecord
  belongs_to :weed
end

Now I want to fetch records from UserTransaction model on the basis of sort by county in weed model.

Please suggest me, How can I get correct result with in minimum complexity.

Thanks.

Aucun commentaire:

Enregistrer un commentaire