Jump to content


set_relation to the same table

set_relation search

  • Please log in to reply
2 replies to this topic

#1 Howard Yang

Howard Yang

    Newbie

  • Members
  • Pip
  • 2 posts

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.

 



#2 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

Posted 26 November 2015 - 03:51 PM

did u try to add name in ->set_relation?



#3 Howard Yang

Howard Yang

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 04 December 2015 - 02:58 AM

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







Also tagged with one or more of these keywords: set_relation, search

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users