Welcome Guest, Not a member yet? Register   Sign In
How to join tables using ORM Datamapper CodeIgniter
#1

[eluser]imohammad[/eluser]
I've spent quite a few hours trying to find out a way of implementing this query:

Code:
SELECT * FROM
        (SELECT * FROM bf_snippets where id IN
        (
            SELECT snippet_id FROM bf_bookmark WHERE user_id = {$user_id}
        )) snippets_table
        JOIN
        (
            SELECT id, language FROM bf_categories
        ) categories_table
        ON snippets_table.category_id = categories_table.id
        JOIN
        (SELECT id , username FROM bf_users) users_table
        ON users_table.id = 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):

Code:
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)




Theme © iAndrew 2016 - Forum software by © MyBB