CodeIgniter Forums

Full Version: How to join tables using ORM Datamapper CodeIgniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I've spent quite a few hours trying to find out a way of implementing this query:

        (SELECT * FROM bf_snippets where id IN
            SELECT snippet_id FROM bf_bookmark WHERE user_id = {$user_id}
        )) snippets_table
            SELECT id, language FROM bf_categories
        ) categories_table
        ON snippets_table.category_id =
        (SELECT id , username FROM bf_users) users_table
        ON = snippets_table.user_id

To ORM Datamapper in Codeigniter. I have 3 models ( user, bookmark, snippet ).

And the relationships are as follows (correct me if it's wrong):

user HAS MANY bookmark and snippet

bookmark HAS ONE user and snippet

snippet HAS MANY bookmark

snippet HAS ONE user
How to implement it using Datamapper in CI? Please note that bookmark is the relation between snippet and user.

Bookmark table has the following attributes (ID, User_ID, Snippet_ID)