mako-framework / framework

Mako framework.
https://makoframework.com
BSD 3-Clause "New" or "Revised" License
242 stars 38 forks source link

ORM Criteria #190

Closed ghost closed 8 years ago

ghost commented 8 years ago

How translate this query to the ORM?

SELECT E.*, A.*
FROM episodes as E
INNER JOIN animes as A
WHERE E.anime_id = A.id AND A.status = 'Ongoing'
ORDER BY E.updated_at DESC LIMIT 15;

I've already tried:

$ongoing = Episode::orderBy('updated_at','desc')->including(['anime' => function($q) {
            $q->where('status', '=', 'Ongoing');
}])->limit(15)->all();

srry bad English.

letr0n commented 8 years ago

Hi,

This should work:

Episode::join('animes', 'animes.id', '=', 'episodes.anime_id')
->where('anime.status', '=', 'Ongoing')
->descending('updated_at')
->limit(15)
->all();
ghost commented 8 years ago

thanks