7937 Posts in 1537 Topics by 944 members
|Go to End|
10 October 2009 at 6:54pm
I'm trying to set the SQL query ORDER BY to DESC on my control loop for the IDOM.
I've got r 301 and added this to the _config file in the dataobject_manager folder:
My images are still sorted in ASC order. Here is the SQL query:
SELECT `Surfboard`.*, `Surfboard`.ID, if(`Surfboard`.ClassName,`Surfboard`.ClassName,'Surfboard') AS RecordClassName FROM `Surfboard` WHERE (SurfboardPageID = '6')
And the query for each individual ID within that query:
SELECT `File`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` WHERE (`File`.`ID` = 46) ORDER BY SortOrder DESC LIMIT 1
It seems like I'd want to set the SortOrder DESC in the first query above, not the second one, as the second query has the LIMIT 1 so a sort order on a single item query is useless. It's the only item so there is nothing to order.
Whereas if the SortOrder DESC was on the first query that pulled all the image IDs, it would sort them all in the preferred manner set in the _config file.
11 October 2009 at 5:00am
I assume you have added SortableDataObject::add_sortable_class("Surfboard"); somewhere?
The thing is, unless you opt out of allowing DOM to handle the Files & Images section of the CMS, File gets automatically added to SortableDataObject to allow drag and drop in AssetAdmin. Therefore, every query for a File is going to append an ORDER BY SortOrder, regardless of the limit.
That your Surfboard query is not showing an ORDER BY clause is a little suspect to me. Are you getting the "allow drag and drop" checkbox on your ImageDOM? Something isn't right there. Try adding the add_sortable_class("Surfboard") to your /mysite/_config.php instead. Better practice, anyway, since then your config doesn't get overwritten with every update.
11 October 2009 at 3:56pm Last edited: 13 October 2009 5:51pm
"I assume you have added SortableDataObject::add_sortable_class("Surfboard"); somewhere?"
No, I didn't. I added this to my mysite/_config file
// Set sort order for SQL queries
I just updated to the r315 and noticed that added a sort order field to my Surfboards table. I had to manually number all the existing entries, but it looks like new entries get a next number added by default. This gets everything to sort in the order that I want it displayed.
I was getting the "Allow drag and drop" checkbox. I was using a pretty old revision on my Production site though.
I just updated my Production site and everything is looking good. Thanks for the help.
12 October 2009 at 4:56am
You shouldn't have had to update the SortOrder manually. It should have done that after the first drag-and-drop.
12 October 2009 at 5:18am
I didn't turn on the drag-and-drop ordering. I didn't want the guy who updates the CMS to have to re-order the boards after every upload.
From what it sounds like you're saying though, is if I had turned it on and drag-and-dropped one image it would have added the sort order to them all. Good to know, but I was trying to get everything working without the drag-drop reording. I want the upload process to be as quick and easy as possible and handle all the sorting automatically on the back-end.
Just got an email from the guy who updates it and he was stoked. Said it worked flawlessly.
I'll play with the drag-and-drop on my DEV site. I haven't set the sort orders on there, so I can see how it handles it.
Thanks again for the help and the great module.
12 October 2009 at 5:28am
Hmm.. Okay, glad it's working. But just a tip.. If you're not going to use drag-and-drop reordering, then you don't need to use SortableDataObject. You just need to add a sort clause to your ImageDOM for "Created DESC"
|Go to Top|