PHP: Active record table joins
问题 I have an app that uses the codeigniter CXTags tagging library. The database structure is as follows: posts id tags_ref row_id table tag_id tags id safe_tag tag My query basically goes if $safe_tag is not null then join tags_ref on post.id = tags_ref.row_id, join tags on tags_ref.tag_id = tags.id, where tags_ref.table = 'posts' and tags.safe_tag = 'food' SELECT * FROM posts JOIN tags_ref ON posts.id = tags_ref.row_id JOIN tags ON tags_ref.tag_id = tags.id WHERE tags.safe_tag = $safe_id