Tags icon indicating copy to clipboard operation
Tags copied to clipboard

Unknown column 'Tagged.fk_table' in 'on clause'

Open bmeclazcke opened this issue 10 years ago • 2 comments

I'm trying to accomplish a search on several fields, including tags.

When trying to use matching or innerJoinWith Tags, I'm getting that error. Following on the query that is generated by CakePHP, I get the following (fragment of query)

... INNER JOIN tags_tags Tags ON Tagged.fk_table = 'projects' INNER JOIN tags_tagged Tagged ON (Projects.id = (Tagged.fk_id) AND Tags.id = (Tagged.tag_id)) ...

Resulting in a crash error: Unknown column 'Tagged.fk_table' in 'on clause'

Thanks!

bmeclazcke avatar Dec 15 '15 22:12 bmeclazcke

What does your behavior configuration look like?

phillaf avatar Dec 16 '15 05:12 phillaf

Same as default one, haven't changed it. After following the instructions and include the behavior in the models, tag saving is working great, just found this bug when using Tags with matching and innerJoinWith like this:

    $projects
                ->where(['LOWER(Projects.name) LIKE' => '%'.$search.'%'])
                ->orWhere(['LOWER(Projects.objectives) LIKE' => '%'.$search.'%'])
                ->orWhere(['LOWER(Users.full_name) LIKE' => '%'.$search.'%'])
                ->orWhere(['LOWER(Tags.label) LIKE' => '%'.$search.'%'])
                ->orWhere(['LOWER(Products.name) LIKE' => '%'.$search.'%'])
                ->matching(['Tags'])
                ->group(['Projects.id']);

If I include the like sentence in the matching/innerJoinWith query as a closure is the same result, trying to extract it as a custom finder. I've given a good 4hs going around and the only solution I found is to customize behavior configuration just for that query. But I was wondering if there's some other workaround that would avoid doing that (because I personally think that's a pretty ugly solution)

Thanks!

bmeclazcke avatar Dec 16 '15 12:12 bmeclazcke