Multiple Mjoin with WHERE clause on same tables - How to taget different editor fields
Multiple Mjoin with WHERE clause on same tables - How to taget different editor fields
peterbrowne
Posts: 314Questions: 54Answers: 0
I have seven (7) similar Mjoins on the same tables, with the only differences being on the WHERE clause, e.g. $q->where( 'discipline_fk', '5' )
Like:
->join(
Mjoin::inst( 'discipline_outcome' )
->name( 'discipline_outcomes_5' )
->link( 'unit_outcome.unit_outcome_pk', 'unit_outcome_discipline_outcome_lookup.unit_outcome_fk' )
->link( 'discipline_outcome.discipline_outcome_pk', 'unit_outcome_discipline_outcome_lookup.discipline_outcome_fk' )
->order( 'discipline_outcome.discipline_outcome asc' )
->fields(
Field::inst( 'discipline_outcome_pk' )
->options( Options::inst()
->table( 'discipline_outcome' )
->value( 'discipline_outcome_pk' )
->label( 'discipline_outcome' )
->where( function ($q) {
$q->where( 'discipline_fk', '5' );
}
),
Field::inst( 'discipline_outcome' )
)
)
)
I will need to target the similar Mjoins to different Editor fields. Currently I have just the one for the above Mjoin:
, {
label: "Discipline Outcome:",
name: "discipline_outcome[].discipline_outcome_pk",
type: "select",
placeholder: 'No selection',
placeholderDisabled: false,
placeholderValue: 0,
multiple: true
}
How can I setup the 7 Editor fields like above for the 7 Mjoins on the same tables, but with different WHERE clause?
This discussion has been closed.
Answers
.
The title should read Target not Taget...
Basically the question is asking if there is another way of targeting which Editor field a join is sending the results to, e.g. in this instance:
I have also asked on Stack Overflow
just create identical views of table "discipline_outcome" with different names. They don't even need to be updatable because you don't update them anyway. Only the link table gets updated. I do this for self-referencing link tables.
My use case is one contract can be the underlying for another contract. E.g. A loan maybe the underlying of a derivative contract.
For internal netting one contract can be the base of another contract as well. So "underlying" is a view on "contract" and "base" is just the same as "underlying", but has a different name.
You could define your views like this. Or specify the fields you really need in the view. Might only be the primary key?!
You can use the
Mjoin->name()
method for what you are looking for. WIth that you can control the JSON / HTTP parameter name that is used, effectively aliasing the table's name to something else.Allan
Thanks Allan.
I thought that there would be a method for using an alias. However, it's not working for me using that method with:
Using the normal approach without the alias name method populates a single select OK, but I need to have the alias working for multiple WHERE queries and corresponding Editor select fields.
Relevant code is:
unit_outcome_data.php:
edit_unit_outcome.php:
Doh! OK I got it working changing the fields in edit_unit_outcome.php to:
and
Works great.
Thanks Allan!
Well something else is now the problem.
When created a new unit_outcome record, and selecting some discipline_outcomes, the lookup table has the records inserted OK.
However, on update, all the records associated with the unit_outcome_fk are deleted in lookup table
unit_outcome_discipline_outcome_lookup
.Existing records in the lookup table also can't be updated in the lookup table,
I think this is just affecting updates to the lookup table
unit_outcome_discipline_outcome_lookup
. The unit outcome in the parent table gets updated OK, e.g. if changing the name of the unit_outcome.This is my current code:
edit_unit_outcome.php:
And in
unit_outcome_data.php:
I suspect, not at all sure, that the UPDATE on
unit_outcome_discipline_outcome_lookup
is failing on the WHERE clauses for the discipline_outcome Mjoins...I think this issue of not updating the lookup table, instead deleting the associated records in the lookup, was the subject of this post:
https://datatables.net/forums/discussion/46958/why-do-multiple-mjoins-on-tbl-with-alias-work-when-creating-records-breaks-when-updating-records
At that time, Allan, you indicated it would be fixed v1.8...
I'm using https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js
.
I've posted a reply in your other thread asking this.
Allan