Closed julianfann closed 7 years ago
This makes a whole lotta sense. A PR would be good.
One note: we shouldn't hardcode the exp_ prefix on the table name, it's configurable in EE. I forget exactly how to get a prefixed table name in Eloquent, but I bet there's an example somewhere in this repo, if not in the Entry model itself.
Using
Entry::fixedOrder($arrayOfEntryIds)
throws this SQL error:Unknown column 'FIELD(68360, 88297, 325, 704477, 448260, 454522)' in 'order clause'
.It is my understanding that to use
FIELD()
in this way, you need to provide the function a column to check against: eg.FIELD(id, 1, 3, 5, 4)
. For most channel entry queries, I think we could get away with something likeFIELD(exp_channel_titles.entry_id, 1, 3, 5, 4)
.Also, Eloquent's
orderBy
scope forces a sort direction which we don't want and will trigger an error itself. eg.order by FIELD(68360, 88297, 325, 704477, 448260, 454522) asc
. We can get around this by usingorderByRaw
instead.I would propose something like this:
Let me know if you want me to make a PR for this or if I'm missing something crucial here.