• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to join tables using ORM Datamapper CodeIgniter

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 = categories_table.id
        (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):

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)

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.