Welcome Guest, Not a member yet? Register   Sign In
Model/Database Relationship?
#6

(07-23-2016, 05:56 AM)idealcastle Wrote:
(07-22-2016, 06:25 PM)JayAdra Wrote: You may want to consider getting this information in a single query using a join - it'll be a lot faster than running four separate queries to get the information, especially at scale.

Yes of course. but that's why I was hoping CI4 had method chaining, like Laravel. Where it uses the query builder to automatically create the joins.

You modify the find() before you call it, not after.

Code:
public function getItem($id)
{
    $post = $this->join('post_files', 'post_files.post_id = posts.id AND post_files.primary = `Y`', 'inner')
                 ->join('post_images', 'post_images.post_id = posts.id  AND post_images.primary = `Y`', 'inner')
                 ->join('post_descriptions', 'post_descriptions.post_id = posts.id  AND post_descriptions.primary = `Y`', 'inner')
                 ->find($id);

    return $post;
}

or something like that.
Reply


Messages In This Thread
Model/Database Relationship? - by idealcastle - 07-22-2016, 03:06 PM
RE: Model/Database Relationship? - by idealcastle - 07-22-2016, 03:29 PM
RE: Model/Database Relationship? - by JayAdra - 07-22-2016, 06:25 PM
RE: Model/Database Relationship? - by idealcastle - 07-23-2016, 05:56 AM
RE: Model/Database Relationship? - by arma7x - 07-23-2016, 06:28 AM
RE: Model/Database Relationship? - by kilishan - 07-24-2016, 09:52 PM
RE: Model/Database Relationship? - by idealcastle - 08-01-2016, 07:48 AM
RE: Model/Database Relationship? - by kilishan - 08-01-2016, 07:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB