How to Submit Data in Mjoin Link Table
How to Submit Data in Mjoin Link Table
Hi Allan,
According this example , and my question here, i need to submit data to the link table between 2 tables (create button)
Let say I have table | field
- act_log_header | act_log_id
- link_log_customer | act_log_id, customer_code
- master_customer | customer_code, customer_name
my php
->join(
Mjoin::inst( 'master_customer' )
->link( 'act_log_head.act_log_id', 'link_log_customer.act_log_id' )
->link( 'master_customer.customer_code', 'link_log_customer.customer_code' )
->fields(
Field::inst( 'customer_code' )
->options( 'master_customer', 'customer_code', 'customer_name' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'customer_name' )
)
)
the insert is only working on link_log_customer.customer_code
link_log_customer.act_log_id
not submitted.
Can it be automatically submitted? or i must using postCreate ? I tried to put Field::inst( 'link_log_customer.act_log_id' ) , but no luck. Please advise, thank you
But it works on edit button
Danny
This question has an accepted answers - jump to answer
Answers
Hi Danny,
Are you able to give me a link to the page so I can debug it directly please? So at the moment when you submit, and it creates a new entry in the
link_log_customer
is it only writing to thecustomer_code
field?Allan
Hi Allan,
Thank you for the respond, here's the test link please take a look
Yes, the
act_log_id
field insert as 0Please help, thank you
Have you fixed this since your post above? The "Customer" field appears to be working as I would have expected.
Allan
Hi Allan,
No I haven't, it still not working for me
New (create) button, can't submit the customer's field
but the Edit button works
I've created a couple of dummy records and I can indeed see it not inserting the customer information. This is sent to the server:
So there is customer information being submitted, it just doesn't appear to be acted upon.
Is
act_log_id
the primary key in theact_log_header
table, and the Editor instance has been told that with the third parameter for the constructor?We might need to do a little debugging here. In the
php/Database/Driver/Mysql/Query.php
file (assuming it is MySQL you are using) there is a commented out linefile_put_contents
, could you put in:and then run an insert with two customers selected and then let me know what the contents of the file is (you might need to change the path of the output file to be suitable for your server).
Thanks,
Allan
Hi Allan,
Yes, here's my full php
Here's the editor_sql result on pastebin
Could you remove the
act_log_head.
part from the primary key please? It shouldn't be required and I wonder if that is what is causing the issue.Thanks,
Allan
Hi Allan,
No luck after remove the
the act_log_head
from the primary key. Test Link updatedThanks for the SQL in pastebin (sorry I missed that link yesterday). That confirms the issue is
act_log_id
:note that
value
in the first array is empty - it should be the id of the row that was inserted into theact_log_head
table.In
Editor.php
you'll find a function called_insert
which has the following code in it:Immediately before that line could you add:
That will let us see exactly what the new row's id is.
I presume it is an auto incrementing column, or is it defined some other way? I'm wondering if this:
is what is causing the problem.
Allan
Hi Allan,
Here's the editor_sql result
Yes it is an auto increment field
Please advise, thank you
Thanks. However, I don't see the text
Insert id:
anywhere in the file. Did it definitely go into_insert
rather than_edit
?Also, could you try changing:
Field::inst( 'act_log_head.act_log_id' )
to be:Thanks,
Allan
Hi Allan,
It works after adding
->set( false )
Thanks again for the help
Danny