⚠ 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

Relation problem



Christian Amberg
  • profile picture
  • Member

Posted 06 July 2015 - 18:35 PM


Hello,

 

 i have the following problem:

 

My main table named cars with fields like id,manufacturer,type,ident.... and color_id

 

i have a second table named colors with fields id, color that looks like:

1,red

2,blue

3,green

...

 

$crud->display_as('color_id','Color');
$crud->set_relation('color_id','colors','color');

 

that works as long as a car has only one color, how can i add multiple colors to one car?

 

i have tried this:

 

$crud->field_type('color_id', 'multiselect');

 

and

 

$crud->field_type('color', 'multiselect')

 

but both variants doesnt work....

 

Do i have to extend the database?

 

 

 


Paul Savostin
  • profile picture
  • Member

Posted 06 July 2015 - 21:30 PM

Hi! How you design your database? For example:

You have next cars - Toyota, BMW, Audi

And colors - white, black, green

So if any of this cars could be any of this colors - Toyota (black, green), BMW(whiite, black, green), Audi (white, green) - this is many-to-namy relation!

So you need table cars, colors and cars_vs_colors - where you write many colors per car. In GC you then will use ->set_relation_n_n