I have models Description
and Click
. Description
has many Clicks
.
How can I sort Descriptions
by column in Click
?
Asked
Active
Viewed 75 times
2

tetiross
- 192
- 3
- 17
1 Answers
3
Try...
Description.joins(:click).order('click.column_name')
If this doesn't work, you may need to call .all before your joins condition, like so:
Description.all.joins(:click).order('click.column_name')

Haseeb Ahmad
- 7,914
- 12
- 55
- 133
-
1@HassebAhmad I got error: `Association named 'click' was not found on Description; perhaps you misspelled it?` But relationships are done well cause when I create click it has description id and everything works good. – tetiross Dec 06 '15 at 00:41
-
1Change click to clicks has many relationship names are pluralized – CWitty Dec 06 '15 at 01:04