You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
Column already exists: 1060 Duplicate column name 'id' (SQL: select * from (select * from `entries` inner join `feeds` on `feeds`.`id` = `entries`.`feed_id` where `feeds`.`category_id` = 2 and `entries`.`deleted_at` is null and `entries`.`user_id` = 1) as `` order by `published` desc, `id` desc limit 16)
I'm thinking the empty as `` might have something to do with it?
Happens when I do:
$entries = $category->entries() // Does not work with `cursorPaginate`.
->orderBy('published', 'desc')
->orderBy('id', 'desc')
->with('feed')
->cursorPaginate();
Where Category has a hasManyThrough relationship with Entry, through Feed (the intermediate model). I.e., an entry belongs to one feed which belongs to one category.
Does not happen when I explicitly do this (i.e., use a whereHas condition):
$entries = Entry::orderBy('published', 'desc')
->orderBy('id', 'desc')
->whereHas('feed', function ($query) use ($category) {
$query->where('category_id', $category->id);
})
->with('feed')
->cursorPaginate();
According to Debug bar, the following SQL is generated for this last bit of code:
select * from (select * from `entries` where exists (select * from `feeds` where `entries`.`feed_id` = `feeds`.`id` and `category_id` = 2 and `feeds`.`user_id` = 1) and `entries`.`deleted_at` is null and `entries`.`user_id` = 1) as `` order by `published` desc, `id` desc limit 16
select * from `feeds` where `feeds`.`id` in (3, 4, 7, 17, 23, 28, 159, 178) and `feeds`.`user_id` = 1
So no JOIN, it seems.
(The user_id = 1 is because of a global scope.)
The text was updated successfully, but these errors were encountered:
Stumbled upon yajra/laravel-datatables#2462 (comment), and it seems adding select('entries.*') to the original code indeed makes it works, too. (No idea why, though.)
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm seeing this SQL error:
I'm thinking the empty as `` might have something to do with it?Happens when I do:
Where Category has a hasManyThrough relationship with Entry, through Feed (the intermediate model). I.e., an entry belongs to one feed which belongs to one category.
Does not happen when I explicitly do this (i.e., use a
whereHas
condition):According to Debug bar, the following SQL is generated for this last bit of code:
So no
JOIN
, it seems.(The
user_id = 1
is because of a global scope.)The text was updated successfully, but these errors were encountered: