⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to set relation on 3 tables



alex646

alex646
  • profile picture
  • Member

Posted 16 June 2013 - 05:30 AM

Hey guys,

 

You helped me quiet a lot last few days, I appreciate it! I have one more issue I can't get my head around:

 

I have 3 tables, users, posts, related posts

 

users has user

posts has post

related_posts has post_id and user_id

 

I've setup relation to users and post table, but I don't know how to set for 3 tables, e.g. how to

relate related_posts, users, and posts. My setup works perfect now except I can't delete a record now, I'm guesssing

it's because relation is not set on these tables correctly.

 

Please advise.

 

Thanks!![attachment=570:Screen Shot 2013-06-16 at 1.29.32 AM.png]

 


davidoster

davidoster
  • profile picture
  • Member

Posted 16 June 2013 - 08:07 AM

Something like this maybe?

 

$crud->set_table('related_posts');

$crud->set_relation('related_postid', 'posts', '{post_category} {post_title}');

$crud->set_relation('user_id', 'users', '{last_name} {first_name}');


alex646

alex646
  • profile picture
  • Member

Posted 17 June 2013 - 02:44 AM

Something like this maybe?

 

$crud->set_table('related_posts');

$crud->set_relation('related_postid', 'posts', '{post_category} {post_title}');

$crud->set_relation('user_id', 'users', '{last_name} {first_name}');

Thanks man! All working now!


Angga Pino

Angga Pino
  • profile picture
  • Member

Posted 03 December 2013 - 16:15 PM

Something like this maybe?

 

$crud->set_table('related_posts');

$crud->set_relation('related_postid', 'posts', '{post_category} {post_title}');

$crud->set_relation('user_id', 'users', '{last_name} {first_name}');

 

how if $crud->set_table('user'); ?

 

my table:

 

Island                            Island_category         category

id_island                       id_category                id_category

id_states                       id_island                    category

id_cities

name_Island

 

I use filters:

 

        $data = $this->db->get('island_category');
        foreach($data->result()as $row):
        $crud->where('Island_category.id_category',$this->uri->segment(3));
        endforeach;

 

 

my columns:

 

$crud->columns('name_island','id_states','id_cities','category');


Giancarlo

Giancarlo
  • profile picture
  • Member

Posted 14 December 2013 - 02:16 AM

hi friends, i need help about join three tables. for example

 

http://stackoverflow.com/questions/14107884/two-tables-in-one-management?answertab=oldest#tab-top

 

i have read many articles about it, and i think the solution is set_model but a dont have an example to use it.

 

Please i need help!!


Giancarlo

Giancarlo
  • profile picture
  • Member

Posted 14 December 2013 - 02:21 AM

My question is how to to get a drop down of other info if in my controller my table is departement

 

set_table("department")

...

...

and i wanna get a dropdown of otherinfo

 

http://stackoverflow...=oldest#tab-top


Racing Chocobo

Racing Chocobo
  • profile picture
  • Member

Posted 21 December 2013 - 03:25 AM

how about this one?

 

[sharedmedia=core:attachments:705]

 

It's quite the same with top question, but the problem is I need to set the table to 'inventory' instead of 'item' since I need to do something with inventory table database, so can't do it if set_table('item');

 

So any solution for this relation with set_table('inventory')?
(When add new record to the inventory, the field item should become dropdown list which list all of the name of the item, instead of the item.id, set_relation(item, item, id) will only make a dropdown list which show only the item.id)

 

Thank you very much!