1
我記得過去的日子「發現」它在查詢使用雄辯,如果我用with
Laravel做inner join
。雄辯的急切加載不會加入?
今天,一個偶然的機會我查了項目的查詢和...
[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"} []
在這種情況下,我做這樣的查詢:
/**
* Get random ocurrences for home
* @return mixed
*/
public static function randomForHome()
{
return static::with('user')
->orderByRaw('RAND()')
->limit(4)
->get();
}
什麼是錯的和/或者我如何與Eloquent聯合?
L4 +不加入表格,我想它實際上從來沒有加入過。 – 2014-11-21 08:51:44
我不認識Jarek。我只記得當我找到一個解決方案,並且這個解決方案沒有使用'join()'。不管怎樣,謝謝。 – 2014-11-21 18:21:46