miso

Fractal transformer: nested include + with()

Posted 3 years ago by miso

Hi, I have models and transformers for Folder, User and Access (Access wraps pivot table folder_user).

This include works fine:

class FolderTransformer extends TransformerAbstract {
    ...
    public function includeAccesses(Folder $folder)
    {
        return $this->collection($folder->accesses, new AccessTransformer);
    }

I would like to include user info (name, email, ...) in the Access include.

I tried this code to SELECT users IN {user ids from the folder accesses}:

    public function includeAccesses(Folder $folder)
    {
        return $this->collection($folder->accesses()->with('user')->get(), new AccessTransformer);
    }

But is this a good practice? Or should I use JOIN instead? How can I enable the nested user include (without defaultIncludes in UserTransformer)?

Thank you

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.