Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
query in DB::select
  • how can i build this query with DB :
    select a.title, a.lead, a.date, a.uri, c.name, (select image from articles_images where article_id = a.id limit 0,1)
    from articles as a inner join articles_category as c on c.id = a.category_id
    where a.confirm_by > 0
    limit 10
    (
    $articles_query = \DB::select(array('a.id', 'id'), array('a.title', 'title'), array('a.lead', 'lead'), array('a.date', 'date'), array('a.uri', 'uri'), array('c.name', 'category'), Model_Article_Images::query()->select('image')->where('article_id', 'a.id')->limit(1)->get_query(false))
                    ->from(array(Model_Article::table(), 'a'))
                    ->join(array(Model_Category::table(), 'c'), 'INNER')
                    ->on('c.id', '=', 'a.category_id')
                    ->where('a.confirm_by', '>', 0)
                    ->limit(10)
                    ->offset(0)
                    ->execute();
    ) not work
  • $image = \DB::select('image')->from(Model_Article_Images::table())->where('article_id', \DB::expr('a.id'))->limit(1);
            $articles_query = \DB::select(array('a.id', 'id'), array('a.title', 'title'), array('a.lead', 'lead'), array('a.date', 'date'), array('a.uri', 'uri'), array('c.name', 'category'), array($image, 'image'))
                    ->from(array(Model_Article::table(), 'a'))
                    ->join(array(Model_Category::table(), 'c'), 'INNER')
                    ->on('c.id', '=', 'a.category_id')
                    ->where('a.confirm_by', '>', 0)
                    ->limit(10)
                    ->offset(0)
                    ->execute();
  • HarroHarro
    Accepted Answer
    A sub-query is indeed just a second query object. This works both in DB and ORM.
  • what is fuel/core/.git directory?
    size: 9.7 Mb

  • HarroHarro
    Accepted Answer
    The git history? You only have that directory if you have a local repository.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion