Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82109

Can't edit (update) join table.

$
0
0
Hello. I have two simple tables: customer and location. In location I have the primary key from customer and a few other attributes. What I want is to join these two tables and be able to edit any of the columns in the resulting table. But it won't let me, saying the following:
An error has occurred - Please contact the system administrator
The response I get is this:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'' in C:....

These are the tables:
A] location[id(PK), Address, CP, City, Country, Phone, Email, Comments, ID_Customer_Location(FK), ID_Partner_Location(FK)];
- ID_Customer_Location is a foreign key. A customer can have more than one location.
- ID_Partner_Location is a foreign key, having to do with another table (Partner).
Both of these keys can be NULL. When I create the location for a customer, ID_Partner_Location is NULL. When I create it for a partner, ID_Customer_Location is NULL.

B] Customer[ID_Customer(PK), Gender, Firstname, Surname, Birthday, Customer_number, ID_Sponsor (FK)];
- A sponsor can have 0 or more customers. There is no separate table for sponsors.


This is the code:

1] PHP:

$editor = Editor::inst( $db, 'location' )
->fields(
Field::inst( 'ID_Customer_Location' ),
Field::inst( 'Address' ),
Field::inst( 'CP' ),
Field::inst( 'City' ),
Field::inst( 'Country' ),
Field::inst( 'Phone' ),
Field::inst( 'Email' ),
Field::inst( 'Comments' )
)
->pkey('id')
->join(
Join::inst( 'customer', 'object' )
->join( 'ID_Customer_Location', 'ID_Customer')
//->set(false)
->fields(
Field::inst( 'ID_Customer' ),
Field::inst( 'Firstname' ),
Field::inst( 'Surname' )
)
);

// The "process" method will handle data get, create, edit and delete
// requests from the client
$out = $editor
->process($_POST)
->data();

// Send it back to the client
echo json_encode( $out );

2] JS:

var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "/index.php/c_datatable/join_location_and_customer",
"domTable": "#location_and_customer_table",
"fields": [ {
"label": "ID_Customer:",
"name": "customer.ID_Customer"
}, {
"label": "Firstname:",
"name": "customer.Firstname"
}, {
"label": "Surname:",
"name": "customer.Surname"
}, {
"label": "Address:",
"name": "Address"
}, {
"label": "CP:",
"name": "CP"
}, {
"label": "City:",
"name": "City"
}, {
"label": "Country:",
"name": "Country"
}, {
"label": "Phone:",
"name": "Phone"
}, {
"label": "Email:",
"name": "Email"
}, {
"label": "Comments:",
"name": "Comments"
}
]
} );

$('#location_and_customer_table').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "/index.php/c_datatable/join_location_and_customer",
"aoColumns": [
{ "mData": "customer.ID_Customer" },
{ "mData": "customer.Firstname" },
{ "mData": "customer.Surname" },
{ "mData": "Address" },
{ "mData": "CP" },
{ "mData": "City" },
{ "mData": "Country" },
{ "mData": "Phone" },
{ "mData": "Email" },
{ "mData": "Comments" }
],
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );


3] HTML:

<table class="display" id="location_and_customer_table" border="0" cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th width="10%">ID_Customer</th>
<th width="10%">Firstname</th>
<th width="10%">Surname</th>
<th width="10%">Address</th>
<th width="10%">CP</th>
<th width="10%">City</th>
<th width="10%">Country</th>
<th width="10%">Phone</th>
<th width="10%">Email</th>
<th width="10%">Comments</th>
</tr>
</thead>
<tfoot>
<tr>
<th width="10%">ID_Customer</th>
<th width="10%">Firstname</th>
<th width="10%">Surname</th>
<th width="10%">Address</th>
<th width="10%">CP</th>
<th width="10%">City</th>
<th width="10%">Country</th>
<th width="10%">Phone</th>
<th width="10%">Email</th>
<th width="10%">Comments</th>
</tr>
</tfoot>
</table>

Can you tell me what I do wrong?

Thank you.

Viewing all articles
Browse latest Browse all 82109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>