⚠ 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

2 Relationships on the same table



juliofagundes
  • profile picture
  • Member

Posted 03 May 2013 - 14:37 PM

I have the following tables and would like to know how to do these two relations:

 


GIFT
gift_id
(...)
tag_id (rel - 1:1 -> tag: tag_id)
tag_id1 (rel - 1:1 -> tag: tag_id)

TAG
tag_id
(...)
genre (M, F)



================================================== ======

 

$ crud-> set_relation ('tag_id', 'tag', 'name', array ('genre' => 'M'));
$ crud-> display_as ('tag_id', 'Male tag');


 
 

working ok.

 

But if, (note tag_id1)
 

 

$crud->set_relation('tag_id','tag','nome', array('genero' => 'Masc'));
                $crud->display_as('tag_id','Male tag');

                $crud->set_relation('tag_id','tag','nome', array('genero' => 'Fem'));
                $crud->display_as('tag_id1','Female tag');

 

Just apears Male tag, seems it doesnt find column tag_id1.

 

 

How can I do this?

 


juliofagundes
  • profile picture
  • Member

Posted 07 May 2013 - 19:27 PM

nobody?


davidoster
  • profile picture
  • Member

Posted 07 May 2013 - 21:45 PM

You can't have multiple relations on the same field.

Why don't you do, 

 

$crud->set_relation('tag_id','tag','nome', array('M' => 'Masc', 'F' => 'Fem'));

 

and just use one field instead of two? 


juliofagundes
  • profile picture
  • Member

Posted 08 May 2013 - 19:34 PM

Because it is necessary to choose two tags to each gift, one male and one female. I Think two separate fields for this choice would be the ideal scenario.

 

But if im wrong, help me see other ways of doing it.


davidoster
  • profile picture
  • Member

Posted 08 May 2013 - 21:24 PM

Then,could you have this?

$crud->set_relation('tag_id','tag','nome', array('M' => 'Masc', 'F' => 'Fem'));

$crud->set_relation('tag_id1','tag','nome', array('M' => 'Masc', 'F' => 'Fem'));


juliofagundes
  • profile picture
  • Member

Posted 09 May 2013 - 14:35 PM

You clarify my mind.

 

the problem was the $crud->fields(...., 'tag_id'). now $crud->fields(...., 'tag_id', 'tag_id1');

 

$crud->fields(..., 'tag_id', 'tag_id1');

 

$crud->set_relation('tag_id','tag','nome', array('genero' => 'Masc'));
$crud->display_as('tag_id','Male tag');

$crud->set_relation('tag_id1','tag','nome', array('genero' => 'Fem'));
$crud->display_as('tag_id1','Female tag');

 

Thanks in advanced man!