Jump to content

Problems with relations in MySQL and Grocery Crud.

MySQL relation

  • Please log in to reply
No replies to this topic

#1 man2000



  • Members
  • Pip
  • 2 posts

Posted 16 February 2017 - 12: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


-rep_id INT Primary Key

-rep_comment Varchar(255)

-rep_area INT



-area_id INT Primary Key

-area_name Varchar(255)

-area_company INT



-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!


Also tagged with one or more of these keywords: MySQL, relation

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users