Many to Many: how it works?

Hello!

I’ve 3 tables: a(id,address), a_b(a_id, b_id), b (id, name)

I’m using Giix and it created correctly the many to many relations. I’ve created 3 records on table B and now I want to display (and save!) them on table “a” . But I have not idea how. And I have no idea how to save this record and display it in a _form and in grid, next.

Any advice, maybe with an example or some code? Thanks and sorry for my english :)

Hello,

I am asking help on the forum to, so I’m gonna try helping you on this one.

so starting from your data scheme




a		a-b		b

-		---		-

id		a_id		id

adress		b_id		name



you should need no code for what you want.

  • first, make sure that in your ‘a-b’ table, both fields are primary keys.

  • then, using giix, use giix model creator for all your tables, using * for example

  • then, use giix crud generator for table ‘a’ and table ‘b’. you can not use it for table ‘a-b’ with a composite primary key, but you don’t need it.

  • you should now have with the url index.php?r=a the possibility to create ‘a’ items. same thing with b.

  • now if you create 3 items in table ‘b’, go on to table ‘a’ to create an item.

you should see below your ‘a’ attributes some checkboxes (one for each ‘b’ item) that allow you to link ‘a’ table to ‘b’ table. In fact this manages the ‘a-b’ table.

I hope this helps

Best regards

Olivier.