Skip to main content

Relation Many to Many

Badaso provides a feature to relate data from a table to other tables. When creating a CRUD, the developer can link a field from one table to another by selecting which field to relate to, the relationship type and the destination table. if you want to use table polymorphism or use relationship Belongs To Many.

To make relation many to many, you must have minimal two table so that can make relation. This feature have two option:

  • First, you can directly create a polymorphism table automatically
  • Second, you can create your own polymorphism table

Set Relation Many to Many#

For use this feature, you can follow the step below:

  • Click button "set other relation". Before add relation many to many

  • Choice relation type, destination table, destination column, and destination column to display. Choice relation

  • but, if you have table polymorphism, you can use that with feature advanced setting and choice polymorphism table. advanced setting

  • After save, you have row like this Before add relation many to many

  • You can save and you have new polymorphism table. Browse relation many to many

Make table polymorphism yourself#

For example, we should create table foo and table boo have relation with table polymorphism. To create a polymorphism table, you can follow the steps below:

  • Before create table polymorphism, create table foo and table boo.

  • To make table polymorphism, Open database management, then click add.

  • Create a table name. Add name table

  • Create two fields with the conditions:

    • The first table name is the same as the first primary table with this format: firsttablename_id. example "foo_id".

    • The name of the second table is the same as the second primary table with this format: secondtablename_id. example "boo_id".

    • Field Type "Big Integer"

    • Check unsigned

    • In the "index" option, select "foreign", click the blue button.

    • First field relation with tabel primary

      Relation first table primary

    • First field relation with tabel primary

      Relation second table primary

    • A pop up will appear, select the primary table.

    • On the "field" menu, select "id".

    • On the type menu, select on delete and on cascade.

  • All fields will look like below. Add field table

  • Click the "accept" button and save