I remember the old "find" that in a query using Eloquent, if I used with
Laravel made a inner join
.
Today I happened to check the queries of a project and ...
[2014-11-20 23:21:16] sql.INFO: select * from 'ocurrences' where 'ocurrences'.'deleted_at' is null order by RAND() limit 4 {"bindings":[],"time":3.58,"name":"mysql"} []
[2014-11-20 23:21:16] sql.INFO: select * from 'users' where 'users'.'id' in ('7') {"bindings":["7"],"time":0.49,"name":"mysql"} []
[2014-11-20 23:21:16] sql.INFO: select * from 'users' where 'users'.'id' = '7' limit 1 {"bindings":["7"],"time":0.51,"name":"mysql"} []
[2014-11-20 23:21:16] sql.INFO: select * from 'tags' limit 5 {"bindings":[],"time":0.41,"name":"mysql"} []
In this case, I'm doing the query this way:
/**
* Get random ocurrences for home
* @return mixed
*/
public static function randomForHome()
{
return static::with('user')
->orderByRaw('RAND()')
->limit(4)
->get();
}
What's wrong and / or how do I do with Eloquent joins?