Issue with 1 - n combination
Issue with 1 - n combination
nessinits
Posts: 86Questions: 27Answers: 0
I use the code underneath to create a 1-n join
->join(
Mjoin::inst( 'to_dossiers' )
->link( 'to_activities.activities_id', 'to_act_dos.activities_id' )
->link( 'to_dossiers.dossiers_id', 'to_act_dos.dossiers_id' )
->order( 'name asc' )
->fields(
Field::inst( 'dossiers_id' )
->options( Options::inst()
->table( 'to_dossiers' )
->value( 'dossiers_id' )
->label( 'name' )
),
Field::inst( 'name' )
)
All my tables have two unique columns (id as an integer and tablename_id as a varchar). As the example above I use the varchar to link the tables, but this results in records with the to_act_dos.activities_id filled to_activities.id instead of to_activities.activities_id.
Does anyone know what I am doing wrong, or is this a bug (or hidden feature). ;-)
Kind regards,
nessinits
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Do you mean that your primary key for the column is a compound key?
If you enable Editor's debug mode (add
->debug(true)
before the->process(...)
statement), it will include the SQL statements it uses in the JSON return. Can you show me that JSON return?Thanks,
Allan
Hi Allan,
No it's not a compound key. I have two separate columns with unique identifiers. The first an integer ('legacy') "id" auto_increment as primary key and the second a varchar "table_id" with a unique generated uuid as a unique key for security purpose.
When you use integer values people can simply try to use different integer values to retrieve data. I use a generated uuid instead, so this is made more difficult.
In the mjoin I use the 'table_id', but somewhere in the core of the PHP the "table_id" is overwritten by the "id". At least that's what I think. I'll give your ->debug(true) a go.
Kind regards,
nessinits
As you can see, I don't use to_activities.id, but to_activities.activities_id. However in the INSERT of to_act_dos the value of to_activities.id is placed into to_act_dos.activities_id.
I see - yes. The libraries are expecting the primary key value (defined by the
->pkey()
method - defaults toid
) from the main table to be used. Let me look into that and get back to you.Thanks,
Allan
I think I know what it is - Editor is struggling with the default parameter of
id
and resolving it when related to the table name of the tables table.I don't know what your
Editor::inst()
constructor, but could you try adding the table name to the pkey field (optional third parameter) - e.g.Thanks,
Allan
It was
I changed it to:
The result is the same ...