ambiguous column
ambiguous column

I added a left join and now am getting ambiguous column error. I thought I caught everywhere that the fields are being used to proceed them with the table name but still get the error. What am I missing?
/*
* Model for DB table Categories
* Created by http://editor.datatables.net/generator
*/
using System;
namespace Billing.Models
{
public class LineItemCategoryModel
{
public int CategoryID { get; set; }
public string category { get; set; }
public string sortby { get; set; }
}
public class LineItemsModel
{
public int LineItemID { get; set; }
public string LineItem { get; set; }
public string CategoryID { get; set; }
public string sortby { get; set; }
}
public class UnitratesModel
{
public string LineItemID { get; set; }
public string effectivedate { get; set; }
public string expiredate { get; set; }
public string unitrate { get; set; }
}
}
/*
* Controller for DB table Categories
* Created by http://editor.datatables.net/generator
*/
using System;
using System.Collections.Generic;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using DataTables;
using Billing.Models;
namespace Billing.Controllers
{
public class LineItemCategoriesController : ApiController
{
[Route("api/LineItemCategories")]
[HttpGet]
[HttpPost]
public IHttpActionResult Categories()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "Categories", "CategoryID")
.Model<LineItemCategoryModel>()
.Process(request)
.Data();
return Json(response);
}
}
}
public class LineItemsController : ApiController
{
[Route("api/LineItems")]
[HttpGet]
[HttpPost]
public IHttpActionResult LineItems()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "LineItems", "LineItemID")
.Model<LineItemsModel>()
.Field(new Field("LineItems.LineItemID"))
.Field(new Field("LineItems.LineItem")
.Validator(Validation.NotEmpty())
)
.Field(new Field("LineItems.CategoryID")
.Validator(Validation.NotEmpty())
.Validator(Validation.Numeric())
.Options(new Options()
.Table("Categories")
.Value("CategoryID")
.Label("Category")
)
)
.Field(new Field("LineItems.sortby")
.Validator(Validation.NotEmpty())
)
.LeftJoin("Categories","LineItems.CategoryID","=","Categories.CategoryID")
.Where("LineItems.CategoryID", request.Form["LineItems.CategoryID"])
.Process(request)
.Data();
return Json(response);
}
}
}
public class UnitratesController : ApiController
{
[Route("api/unitrates")]
[HttpGet]
[HttpPost]
public IHttpActionResult Unitrates()
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "unitrates", "UnitRateID")
.Model<UnitratesModel>()
.Where("LineItemID", request.Form["LineItemID"])
.Process(request)
.Data();
return Json(response);
}
}
}
}
This discussion has been closed.
Answers
here is the js
oh, by the way, I am getting the error that CategoryID and sortby are ambiguous.
and it is for tableID: LineItems
Sorry, I figured out the ambiguous issue. I needed to bring the model of the table I was joining:
but now I am having an issue getting the selected row data. I can't figure out the correct syntax. Error: 'CategoryID' of undefined
I also tried:
d.LineItems.CategoryID = selected.data().Categories.CategoryID;
and
d.LineItems.CategoryID = selected.data().LineItems.CategoryID;
and none of these worked.
I will open this as a new thread
Hi,
Good to hear you got the SQL issue sorted out. For the issue on how to get the data -
I believe should do it.
But if it doesn't add
console.log(selected.data())
into the code at that point and have a look at the data structure in the browser's console.Allan
turns out the solution for this second issue was:
d['LineItems.CategoryID'] = selected.data().CategoryID;