This project is archived and is in readonly mode.
Column 'created_at' in order clause is ambiguous on queries with include
Reported by Quantum | May 2nd, 2011 @ 06:35 PM
ObjectItem HABTM ObjectGroup and ObjectGroup HABTM ObjectItem. I have the following query that is working correctly:
ObjectItem.find(:all, :include => :object_groups,
:conditions => "object_items.description LIKE '%#{search}%' OR
object_groups.description LIKE '%#{search}%'", :order =>
'object_items.created_at DESC')
But doing query this way is now deprecated so i'm trying to change to this form
ObjectItem.order('object_items.created_at
DESC').includes(:object_groups).where("object_items.description
LIKE '%#{search}%' OR object_groups.description LIKE
'%#{search}%'")
But i'm getting the following error:
Mysql2::Error: Column 'created_at' in order clause is
ambiguous: SELECT DISTINCT object_items.id FROM object_items LEFT
OUTER JOIN object_groups_object_items ON
object_groups_object_items.object_item_id = object_items.id LEFT
OUTER JOIN object_groups ON object_groups.id =
object_groups_object_items.object_group_id WHERE
(object_items.description LIKE '%%' OR object_groups.description
LIKE '%%') ORDER BY object_items.created_at DESC, created_at DESC
LIMIT 20 OFFSET 0
No comments found
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>