Joining tables.
Joining tables.

Hi Allan,
My previous question (about the SQL) stemmed from the following.
I have Table A, with a foreign key to Table B, which has a list of values (a lookup table). I have no issue displaying all of the values in Table B in a combo box (using select or selectize) and updating.
If I changed it so that table B now has (only) two foreign keys--one to Table C (with values for manufacturers) and one to Table D (with values for brands), I still can display the values, but when I update (select another value), it is not reflected in the Datatable.
Is this doable?
Answers
Can you show me the PHP code you are using for that? Is it writing changes to Table B for the foreign keys?
Can you also add
->debug(true)
before->process(...)
(if you don't already have it) and show me the response from the server for an edit request?Thanks,
Allan
Allan asked for the response from the edit request that introduces the error. What you posted above looks like a the response to a
draw()
request.Kevin
There is no "error"--just not working as I expect.
The Datatable looks fine.
In the Editor, the Manufacturer and Brand do not display.
I think that rather than the following ids being returned from the server for companies
I want the actual manufacturer and brand names, but I cannot figure that out.
Sorry, I don't understand what "and updating" means in this context.
But let me try to understand this.
I see you have an "items" table. One row in that table is the item "Internal Hard Drive". This table has one direct link (via foreign key, no link table!) to the "companies" table. The foreign key in "items" is "items.company_id". "Companies" itself has direct links (also foreign keys) to "manufacturers" and "brands". The foreign keys in "companies" are "companies.manufacturer_id" and "companies.brand_id".
The database design means:
- One "item" can be assigned to a "company". It cannot be assigned to a "manufacturer" or a "brand" directly.
- This implicitly means: It doesn't make a lot of sense to have dropdowns to select "manufacturer" and "brand" for an "item". Instead you need a dropdown for "company".
- If you select a "company" for an "item" you have implicitly selected "brand" AND "manufacturer" because they come with "company"!
This is the code that is "telling" me the above:
The code below cannot work because working on table "items" you simply cannot select a "brand" or a "manufacturer". All you can select is a "company" that implicitly contains the selection of "brand" and "manufacturer" because "company" contains both foreign keys. In addition it doesn't make much sense to update fields in "manufacturers" and "brands": The foreign keys are in table "companies"; you only need the options from tables "manufacturers" and "brands", but you don't update those tables.
You would need something like this if you really wanted to make this work (but you probably won't want this because it is not the "business outcome" you want to achieve, I guess.)
Depending on what you are really trying to achieve you may have to redesign your application OR your database. Good luck!
Roland
Good morning Roland,
Very perceptive. This is a change that I made in the last 24 or so hours. Manufacturer and brand were in the items table, as well as web--and everything worked.
Then it occurred to me that an item doesn't have a web address--and brand does! (One manufacturer may have many brands, each with a different web address.)
So... this was an attempt to rectify this.
It has also occurred to me--almost from the beginning--that my new design is wrong, and hence the issue.
Your comments above are **much appreciated! **