Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Try specifying column names in ->get()

Something like

Post::with('categories')
->leftJoin('post_author as pa', 'pa.post_id', '=', 'posts.id')
->get(['categories.name', 'posts.text', 'post_author.name']);
Last updated 9 years ago.
0

This results in columns not found. I just don't understand why it ignores everything within the with() function when you add join to eloquent query.

0

Similar query is working for me :/ But i think it has something to do with same column names/values (like IDs, etc...) and eloquent cant handle it... but i may be off

Last updated 9 years ago.
0

I had a similar issue. Maybe looking at my thread will shed some light on your problem: http://laravel.io/forum/12-11-2014-eloquent-confused-about-which-id-column-to-use-when-using-a-join-with-eager-loading

0

@VenomRush Exactly - if you join tables in Eloquent, always specify the columns to select, otherwise Eloquent will get confused and will give you unexpected results. Even if it doesn't look like at first glance.

0

Just had the same problem. When you add the select(['post.*']) method it will work. Seems like the internals get a bit confused. This was my first hit on Google, thats why i dropped the solution here :-).

0

Sign in to participate in this thread!

Eventy

Your banner here too?

d1001001 d1001001 Joined 10 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.