MJoin + Left Join
MJoin + Left Join
Hello,
is there an option to use mjoin and left join in the same server side script?
or multiple mjoins?
haven't found the syntax for this.
thank you
mg
if I use
...
->join(
Mjoin::inst( 'Aufgaben_Kundenprojekte' )
->link( 'Projekte_Kundenprojekte.ID', 'Aufgaben_Kundenprojekte.Projekt_ID' )
->fields(
Field::inst( 'ID' )
)
)
->link('Kunden.ID', 'Projekte_Kundenprojekte.ID')
->fields(
Field::inst('ID'),
Field::inst('Abkuerzung')
)
...
DataTables warning: table id=projekte_kundenprojekte - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Tabels look like:
Projekte_Kundenprojekte
ID PMSchluessel Beschreibung Statusmeldung Zieldatum Verantwortlich Modus Kunde_ID
Kunden
ID Firmenname Notizen Ansprechperson EMail Telefon Abkuerzung
Replies
there is no special syntax for this; you just use multiple left and Mjoins in one query. That's all.
Like this for example:
... or this:
@rf1234 thank you!
I forgot the ->join before
(I want to show the data in a Select item)
Don't understand question 1.
Question 2.: with an options instance. You see one in my reply above in the first Mjoin. Here is more on it: https://editor.datatables.net/manual/php/joins
Scroll down to "Options".
This is the javascript for the options instance in the example above using a select field. https://editor.datatables.net/reference/field/select
Question 1 is about how do you post your code snippets in this forum? because I do not find the layout
Question 2 is I have linked both tables with a mjoin, but I can't access the field, the select box isn't filled.
Question 1:
You can copy & paste them if you don't find the back ticks on your key board.
Question 2:
Well, then there's something wrong with your code ... I guess. In my example above the options instance returns an array of rendered data. The field is called "prefixed_id" as in ->value on the server side.
On the client side it must be accessed as an array as in "predecessor[].prefixed_id". "Predecessor" being the table as in ->table on the server side.
Another example for the options instance to make it a little easier hopefully. The first client side field is an options instance for a field that is NOT contained in an Mjoin. The second one is an Mjoin options instance. You see the difference looking at "name:".
And the respective server side code:
@rf1234
JSON
Server
Client
Here would be a "demo", maybe it is because I have a child table - https://drakul.eu/testing/datatable/
There might be a data modelling issue?!
The relationship between your tables
Projekte_Kundenprojekte
ID PMSchluessel Beschreibung Statusmeldung Zieldatum Verantwortlich Modus Kunde_ID
Kunden
ID Firmenname Notizen Ansprechperson EMail Telefon Abkuerzung
is 1:N with "Kunden" being the parent table. For that you don't use an MJoin! A simple left join will do.
In addition there is no options instance in your server side code. This way it won't work.
If you take a look at this you'll see an excerpt from my data model that is exactly about my code example.
The relationship between report_type and report is the same as the one between Kunden and Projekte_Kundenprojekte. The foreign key in report is "report_type_id". And that is precisely the field that is being filled with my options instance above.
The mJoin is only needed if you have an N:M relationship requiring a link table. The link table in my example to resolve the N:M relationship between "report" and "govdept" is called "report_has_govdept". This table is being edited (create and delete of link table rows) by the MJoin. The options instance in the MJoin allows you to chose a department (= govdept) and upon saving your selection it creates link table entries.
The link (i.e. the link table fields) is specified here:
@rf1234 thank you - now this is clear to me!
my problem is if I try a left join select is also without data and I can't access my child table anymore, do you have an idea where I am hanging?
parten table php
child table php - it is always the if entered, without the if the is an error
(Notice: Undefined index: Aufgaben_Kundenprojekte.PMSchluessel in /var/www/clients/client1/web3/web/self_build/php/aufgaben_kundenprojekte.php on line 31)
javascript
In this code the left join is redundant because you are not selecting any fields from the left joined table. The MJoin seems wrong too because you seem to have a foreign key from "Projekte_Kundenprojekte" in your child table "Aufgaben_Kundenprojekte". In that case you don't need an MJoin. And here as well: You are not selecting anything from the MJoined table.
My impression is that you need to gain clarity on your data model first. And you have this field "PMSchluessel" that isn't an ID field but seems to play a similar role as a foreign key or even is a foreign key?!
What is it actually that you want to do?
Do you want to assign tasks ("Aufgaben") to a project ("Kundenprojekte")? If you tell me what you want I might be able to help. Please also clarify what this PMSchluessel is all about. Since you have a foreign key from "Kundenprojekte" already in "Aufgaben" you don't need "PMSchluessel" to define the relationship. It looks pretty much redundant.
@rf1234 thank you for your patience!
For the structure see the pdf document attached.
1) Now I got the 1:n for Kunde working
2) The mjoin was copied by this tutorial https://datatables.net/blog/2019-01-11 and a little bit adapted so it counts the amount of "aufgaben" for the different "project_id"s.
3) Yes you are right I want to assigns tasks ("Aufgaben") to a project ("Kundenprojekte") - the "PMSchluessel" is an automatically generated Key with a increasing number, the name of the customer ("Kunden.Abkuerzung") and a manuel added Text ("Projekte_Kundenprojekte.Bezeichnung")
4) It would be also necessary to save status updates in a table to look back how the project has developed and load the newest status from this table("Statusberichte_Kundenprojekte") to the task("Aufgabe") or project ("Projekte_Kundenprojekte")
Hope it is now clear to you what I want to build.
5) What do you think, how would it be best to assign tasks to projects and also count the open (where clause) tasks of the project?
!(https://datatables.net/forums/uploads/editor/a9/lq7c6bdyzuud.pdf "")
Hi there, will switch to German now. For everyone else reading this: Use deepl.com please to translate this into English if required.
Guten Morgen!
Zu 1) freut mich!
zu 2) ok verstanden! Hier geht es darum, einfach nur mehrere Werte pro Zeile der Parent Tabelle anzuzueigen; dafür ist ein MJoin genau das richtige. Wenn es darum geht, Werte zuzuweisen, die logisch in einer 1:N Beziehung stehen, braucht man keinen MJoin. Den bräuchte man nur, wenn man eine Link Tabelle hätte zur Auflösung einer N:M Beziehung, die es in Deinem Modell nicht gibt.
zu 3) ich versuche es mal
Mit dieser Editor Instanz kannst Du eine Aufgabe einem Projekt zuweisen. Ich habe das Ganze bewusst einfach gehalten.
In dieser Editor Instanz wird nichts zugewiesen. Hier werden lediglich die Projekte mit Ihren Aufgaben dargestellt. Ein Projekt hat N Aufgaben. Die Aufgaben werden als Wiederholungsgruppe in einem Feld des Data Table dargestellt. Hierfür kann man den MJoin gut verwenden.
4) Du könntest beispielsweise ein Log schreiben oder Ähnliches hierfür stehen die PHP Events zur Verfügung.
Hier ein Beispiel für das Log; du kannst natürlich auch jegliche andere Art von Update machen.
5) Den Aufgabenstatus könntest Du ebenfalls im MJoin mit selektieren und anschließend auch die offenen Positionen auf der client Seite mit reduce zählen und irgendwo anzeigen
https://datatables.net/reference/api/reduce()
Dazu findest Du auch irgendwo im Forum ein Beispiel von @allan
Viele Grüße
Roland
@rf1234
Danke Roland!!!
Ich werd mich mal durch die Codezeilen bewegen, jetzt habe ich alle Informationen geballt vor mir - da sollte ich schon was drauß zaubern können!!!!!!!
Nochmals DANKE!!!!