⚠ 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

Problems with relations in MySQL and Grocery Crud.



man2000
  • profile picture
  • Member

Posted 16 February 2017 - 00:57 AM

I am far from an DB expert but done some work using DB´s before. And i thought it would be nice to use Grocery Crud for a project that i am re-writing from another guy who initialy wrote it. I think it´s a case of "bad DB design"...but i really don´t wan´t to mess around with the existing structure (i removed some fields for readability).

 

Here is my tables

 

report
-rep_id INT Primary Key

-rep_comment Varchar(255)

-rep_area INT

 

area

-area_id INT Primary Key

-area_name Varchar(255)

-area_company INT

 

company

-c_id INT Primary Key

-c_name Varchar(255)

 

What i want it so when i do $crud->set_table('report');

I want to fetch all the reports. And then fetch the name of the area and the name of the company.

But there is a problem here. The is a relation between "report.rep_area" and "area.area_id". So that works....but how do i get the company name from the company table?

I tried using area as a junction table with "set_relation_n_n"

But my "set_relation_n_n" field is empty.

 

Am i right in that i probobly need to add a new field to the report table that has a relation directly to company table?

 

Or is there another way to solve this?

 

Thanx in advance!