⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation to the same table



Howard Yang

Howard Yang
  • profile picture
  • Member

Posted 25 November 2015 - 04:26 AM

I have a problem when using tree categories structure, parent_id is a foreign key to the category id.

->set_relation('parent_id', 'categories', 'display_name')

Everything is ok when add or edit, but when i filtering some column in list, it show ambiguous column name sql error.

Column 'seq' in where clause is ambiguous

SELECT `categories`.*, j6be37982.display_name AS s6be37982, `categories`.display_name AS 'categories.display_name' FROM `categories` LEFT JOIN `categories` as `j6be37982` ON `j6be37982`.`id` = `categories`.`parent_id` WHERE `seq` LIKE '%1%' ESCAPE '!' LIMIT 10

Here is my table schema

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(10) unsigned NOT NULL,
  `parent_id` int(10) unsigned DEFAULT '0' ,
  `layer` tinyint(3) unsigned DEFAULT '0' ,
  `name` varchar(64) NOT NULL ,
  `display_name` varchar(255) NOT NULL ,
  `seq` mediumint(8) unsigned NOT NULL DEFAULT '999',
  `created_at` datetime NOT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8;

I know the solution is to add table name before the field name when set relation to self.

But i can't find where to put code in grocery library.

 


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 26 November 2015 - 15:51 PM

did u try to add name in ->set_relation?


Howard Yang

Howard Yang
  • profile picture
  • Member

Posted 04 December 2015 - 02:58 AM

Where to add it? in $field_name argument or $related_title_field ?