Join with table rename
Join with table rename
marianidiego
Posts: 50Questions: 15Answers: 1
in Editor
Link to test case: https://editor.datatables.net/examples/advanced/joinArray
Description:
It would be interesting to be able to change the name of the linked table. Like: "Mjoin::inst( 'permission as permission' )" .
This might be useful in some circumstances....
Replies
... and it is already possible!
Just create a view in you database and use it.
Example from my own coding:
- I created a view on "contract" which I call "underlying". Then I created a link table that links derivative contracts with their "underlying" contract. Meaning a link table between "contract" and itself.
Now I can create an Mjoin that allows me to select underlyings for derivative contracts. Both are in the contract table of course. ("Naked" derivatives are illegal for my clients. They must have and assign an "underlying" contract they want to hedge.)
This is the Mjoin:
Not exactly.
I already use views in sql...
But exactly, these each one has a different name. I have different views, to extract data for different circumstances. If I can rename the table to datatables, I can use the same code each time.
If I declare a
Editor::inst( $db, 'product_special_clients as products', 'products_id' )
this will work without any problems.
But if I use a
This will not work.
ok, then define those different table names as (global) variables and get them into the code that way. Shouldn't be any problem.
If you have trouble having the right table name available in your code use a $_SESSION variable for example that you can set elsewhere depending on your context. That way your code becomes very flexible.
Here is a WHERE clause that is different for each context depending on how certain session variable are set. For certain contexts the WHERE clause isn't applicable at all for example, see first "if" condition. Hence I can use the same Editor instance for client users with restricted rights and for internal admin users with unlimited rights. I also use different table names in the SQL depending on the situation.
I need to look at what will be involved in supporting that directly. I can see that it might be useful. Thanks for the suggestion.
Regards,
Allan