Question

i have two joined tables. Now i need to print out some columns, but problem is that i have Firms.Id and FirmsUnique.Id columns. When i try to ->select("*") kohana 3.2.0 throws error: "Column 'Id' in order clause is ambiguous"

$firms = ORM::factory('firm')
    ->select("Firms.Id", "FirmsUnique.*")
    ->join("firmsunique")
    ->on("Firms.FirmUID", '=', 'FirmsUnique.Id')
    ->order_by('Id', 'ASC')
    ->where('ProjectId', '=', $projectid)
    ->group_by("FirmsUnique.FirmName")
    ->limit($pages->items_per_page)
    ->offset($pages->offset)->find_all();

How do i deselect column? Or i have to type manualy all columns that i want? (->select("Firms.Id", "Firms.ProjectId" ... etc))

Was it helpful?

Solution

->order_by('Id', 'ASC')
->where('ProjectId', '=', $projectid)

to

->order_by('Firms.Id', 'ASC')
->where('Firms.ProjectId', '=', $projectid)

Also you can use echo $firms->compile(Database::instance()); before calling find_all() method to inspect your query and try to execute it in MySQL directly to find some bugs and errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top