Editor: MJoin Error: Join was performed on the field x which was not included...
Editor: MJoin Error: Join was performed on the field x which was not included...
Hello,
I'm using the datatables editor with .Net. I'm doing an MJoin on three tables, Jobs, ProdData, and Dept. So a job (table 1) has a jobID that is a FK to ProdData, which has a DeptID, linking it to the Dept table. Jobs to ProdData is a one to many, and ProdData to Dept is a one to one. When I execute my code, I get the following error: "DataTables warning: table id=ProductionData - Join was performed on the field 'logan_jobs.jobID' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance." The issue is, I have placed logan_jobs.jobID in the Editor field list already, but it's still throwing the error. Any assistance would be much appreciated.
Controller:
public IHttpActionResult ProductionData()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "logan_jobs", "jobId")
.Model<ProductionDataModel>()
.Field(new Field("logan_jobs.jobID")
.Set(false))
.Field(new Field("logan_jobs.jobNumber"))
.Field(new Field("logan_jobs.customer"))
.Field(new Field("logan_jobs.plannerID")
.Options("logan_user", "userID", "fullName", q => q.Where("deptID", "1", "="))
.Validator(Validation.DbValues()))
.Field(new Field("logan_jobs.description"))
.Field(new Field("logan_jobs.partNumber"))
.Field(new Field("logan_jobs.salesOrder"))
.Field(new Field("logan_jobs.OrderDate"))
.Field(new Field("logan_jobs.QuoteNumber"))
.Field(new Field("logan_jobs.ShipByDate"))
.Field(new Field("logan_jobs.NeedByDate"))
.Field(new Field("logan_jobs.CloseDate"))
.Field(new Field("logan_user.fullName"))
.MJoin(
new MJoin("logan_proddata")
.Link("logan_jobs.jobID", "logan_prodData.jobID")
.Model<ProductionDEPTDataModel>()
.Order("displayOrder, department")
.Field(new Field("logan_deptData.department"))
)
.LeftJoin("logan_user", "logan_user.userID", "=", "logan_jobs.plannerID")
.Process(request)
.Data();
return Json(response);
}
}
Models(2):
public class ProductionDataModel : EditorModel
{
public class logan_jobs : EditorModel
{
public int jobID { get; set; }
public string jobNumber { get; set; }
public string customer { get; set; }
public string description { get; set; }
public string partNumber { get; set; }
public int plannerid { get; set; }
public string salesOrder { get; set; }
public string OrderDate { get; set; }
public string QuoteNumber { get; set; }
public string ShipByDate { get; set; }
public string NeedByDate { get; set; }
public string CloseDate { get; set; }
}
public class logan_user : EditorModel
{
public string fullname { get; set; }
public int userid { get; set; }
}
}
----
public class ProductionDEPTDataModel : EditorModel
{
public class logan_deptData : EditorModel
{
public int deptID { get; set; }
public string department { get; set; }
public int displayOrder { get; set; }
}
}
Javascript:
function format(d) {
// `d` is the original data object for the row
return '<table cellpadding="15" cellspacing="0" border="0" style="padding-left:50px; width:75%;">' +
'<tr>' +
'<td><a href="jobs_details.aspx?jobNumber=' + d.logan_jobs.jobNumber + '"><img src="img/icons/white-zoom-icon.jpg" title="View Details" target="_blank" width="20px"/></a></td>' +
'<td style="font-weight:bold">Part Number:</td>' +
'<td>' + d.logan_jobs.partNumber + '</td>' +
'<td style="font-weight:bold">Ship By:</td>' +
'<td>' + d.logan_jobs.shipByDate + '</td>' +
'</tr>' +
'<tr>' +
'<td></td>' +
'<td style="font-weight:bold">Sales Order:</td>' +
'<td>' + d.logan_jobs.salesOrder + '</td>' +
'<td style="font-weight:bold">Quote Number:</td>' +
'<td>' + d.logan_jobs.quoteNumber + '</td>' +
'</tr>' +
'</table>';
}
(function($){
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: './api/ProductionData',
table: '#ProductionData',
fixedHeader: true,
fields: [
{
"label": "JobID:",
"name": "logan_jobs.jobID",
"type": "readonly"
},
{
"label": "Job:",
"name": "logan_jobs.jobNumber",
"type": "readonly"
},
{
"label": "Customer:",
"name": "logan_jobs.customer",
"type": "readonly"
},
{
"label": "Planner:",
"name": "logan_jobs.plannerID",
"type": "select"
},
{
"label": "Description:",
"name": "logan_jobs.description",
"type": "textarea"
},
{
"label": "PM Date:",
"name": "logan_prodData[].PMEnd"
}
]
});
var table = $('#ProductionData').DataTable( {
ajax: './api/ProductionData',
order: [ 1, 'asc' ],
fixedHeader: true,
columns: [
{
"class": "details-control",
"orderable": false,
"data": null,
"defaultContent": "<img src='img/icons/blue-plus-icon.png' title='View Details' width='16px' />"
},
{
"data": "logan_jobs.jobID"
},
{
"data": "logan_jobs.jobNumber"
},
{
"data": "logan_jobs.customer"
},
{
"data": "logan_user.fullName"
},
{
"data": "logan_jobs.description"
}
],
select: true,
lengthChange: false
} );
new $.fn.dataTable.Buttons(table, [
{ extend: "edit",
editor: editor,
formButtons: [
'Save',
{ label: 'Cancel', fn: function () { this.close(); } }
]
},
{
extend: "remove",
editor: editor,
formMessage: function (e, dt) {
return 'Are you sure you want to delete this record?';
},
formButtons: [
'Delete',
{ label: 'Cancel', fn: function () { this.close(); } }
]
},
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
] );
table.buttons().container()
.prependTo($('div.fg-toolbar:eq(0)', table.table().container()));
// Add event listener for opening and closing details
$('#ProductionData tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(format(row.data())).show();
tr.addClass('shown');
}
});
} );
}(jQuery));
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
My apologies for the ugliness of this post.
Could you remove:
And also the
jobID
from thelogan_jobs
class please? Editor will include them automatically and I think that might be confusing it.Thanks,
Allan
That resolved the existing error, but now I get a new error: "Not unique table/alias: 'logan_proddata'"
Controller is:
That's odd! Can you show me the code for your two models please?
Thanks,
Allan
"Not unique table/alias: 'logan_proddata'"
Controller:
Models:
Could you try changing the code a little:
1) Remove the table prefix from the
MJoin
elements:2) Remove the nested class from the MJoin model. Although nested classes are used for the left join, they (possibly confusingly) aren't for MJoin:
Thanks,
Allan
Okay, made those changes. Now I am back to the original error: Join was performed on the field 'logan_jobs.jobID' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance.
Any ideas?
I'm afraid I think there is a bug in Editor here. When it is checking to see if the joined field is the primary key, it should use the table name as well.
Could you try changing:
To be:
That should workaround it until it is fixed properly.
Thanks,
Allan
Still getting the same error. Here's my whole response variable, as it stands now:
Is there any other work arounds you can think of to get this going? If not, when will the bug fix be released?
Can I send an e-mail with an updated dll to the e-mail address you used to register your account? The latest changes should address what you are seeing.
Regards,
Allan
Yes, please do. Thank you so much.
Okay, new problem (maybe??). I have changed the controller quite a bit, but am still doing the MJoin.
I have logan_prodData as the main table here, doing an MJoin to logan_jobComments (one production data record can have multiple comments). The link between the tables is the JobID.
The error I now get, using the new dll is:
DataTables warning: table id=ProductionData - Column 'jobID' in field list is ambiguous
Controller Code:
Are you using the dll I sent by e-mail? If so, can you add
.Debug( true )
in between lines 3 and 4 in the above code (i.e. immediately after the constructor) and then show me the JSON that the server is returning please?Thanks,
Allan
Added, this is what I get from the API:
This is the model I am using, and the ambiguous error is on the last line. If I remove it or rename it to an alias, I get the original error that it was not included in the field list.
Sorry this is dragging on somewhat! I'll update the dll shortly and ping it through to you again - it looks like it isn't collecting the SQL if an error occurs, which isn't very useful!
Allan
Okay, thanks. Appreciate the assistance!
Alright, here it is...looks like jobID is being included in the select list (last column) but it does not have a table qualifier on it, thereby making it ambiguous. Note that it's not a field column I am adding, as my addition of jobID is the second column, logan_prodData.jobID.
Okay - got it. Thanks!
Try this for your
DepartmentDataModel
:The problem is that without that inner class, Editor doesn't "know" that the fields are really join fields - so it is adding them as defined in the model.
Allan
Okay, that fixed that particular problem, now I get:
DataTables warning: table id=ProductionData - Join was performed on the field 'logan_prodData.jobID' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance.
But the field is in the list.
Here's the debug:
I think its because of the case difference:
v
A direct string compare (which Editor does) is going to fail because `"logan_proddata" != "logan_prodData"
If you make it consistent -
logan_prodData
for example - I think it should work.Allan
So the MJoin is on logan_jobComments (see the post from Oct 11):
Also verified that all cases of logan_prodData were the same, just to be sure that wasn't it. And from the same post on Oct 11, logan_prodData.jobID is the first field that is listed, so I am not sure why it would be saying it's not in the editor list.
The whole controller request variable:
Sorry - I got that from the Oct 7th post.
I think this is a bug in the Editor library that is being triggered by the fact that
.Field(new Field("logan_prodData.jobID"))
has the table name on it as well as the column name. If you were to use.Field(new Field("jobID"))
I suspect it would work.Let me dig into this a bit more. I'll create a local example and try to replicate the issue.
Regards,
Allan
No, it apparently has to have the table name in the field. New error when I remove the table name from the field definition:
Table part of the field 'jobID' was not found. In Editor instance that use a join, all the fields must have the database table set explicity.
No debugSQL was generated this time.
Okay - thanks for letting me know. Let me look into it, while I'll do as quickly as possible, and get back to you. I can see the issue in the code, I'm just not immediately certain what the best way to fix it is.
Allan
So I worked around the insert by creating a field in my main table, logan_prodData for a single comment, then created a trigger on that table in the database to move the comment from the main table to the "real" table that it's needed in. The only downside is that the users still cannot view the comments in the datatable, they have to view them on a custom .net C# page.
Hi,
just ran into the same problem.
Is there a solution yet?
Eisenkiefer
I've not had a chance to work out what is going on here yet I'm afraid (plan to soon though!). I think that it is an error in the libraries where the joining field is not the primary key. Would that match your case Eisenkiefer? Could you post your code so I can take a look for similarities?
Thanks,
Allan
Yeah that would match my case, the joined is performed on a foreign key in the main table.
Code looks pretty much similiar to the above, i will post the exact code later.
Thanks for your support
Eisenkiefer