⚠ 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

the problem with using $crud->where, and $crud->set_relation



Akylenok

Akylenok
  • profile picture
  • Member

Posted 15 September 2012 - 12:44 PM

the problem with using $crud->where, and $crud->set_relation

my code:


$crud = new grocery_CRUD();

$crud->set_theme( 'datatables' );
$crud->set_subject( 'Товар / Работу / Услугу' );
$crud->set_table( 'entry' );
$crud->where( 'entry_type', 8 );

$crud->set_relation( 'entry_category', 'entry', 'entry_name', array( 'entry_type' => 7 ), 'entry_name ASC' );

$crud->display_as( 'entry_type', 'Тип записи' )
->display_as( 'entry_date', 'Дата и время' )
->display_as( 'entry_url', 'URL псевдоним' )
->display_as( 'entry_photo', 'Изображение' )
->display_as( 'entry_name', 'Название' )
->display_as( 'entry_content', 'Содержание' )
->display_as( 'entry_desc', 'Адрес ролика на YouTube' )
->display_as( 'entry_t', 'TITLE' )
->display_as( 'entry_k', 'KEYWORDS' )
->display_as( 'entry_d', 'DESCRIPTION' )
->display_as( 'entry_category', 'Категория' );

// отображаемые колонки и порядок вывода
$crud->columns(
'entry_name',
'entry_url',
'entry_category'
);

// отображаемые поля и порядок вывода
$crud->fields(
'entry_type',
'entry_name',
'entry_url',
'entry_category',
'entry_content',
'entry_t',
'entry_k',
'entry_d'
);

// невидимые поля
$crud->change_field_type( 'entry_type', 'invisible' );

// обязательные для заполнения поля формы
$crud->required_fields(
'entry_name',
'entry_url',
'entry_category',
'entry_content',
'entry_t',
'entry_k',
'entry_d'
);

// отключение текстового редактора для полей
$crud->unset_texteditor(
'entry_t',
'entry_k',
'entry_d'
);

// добавляем функционал
$crud->add_action( 'Галерея', '', '', 'ui-icon-image', array( $this, '_edit_gallery' ) );

// Перед записью
$crud->callback_before_insert( array( $this,'_callback_before_insert_shop_items' ) );

$output = $crud->render();
$output->header = 'Товары / Работы / Услуги';
$this->_example_output($output);


my MySQL:


CREATE TABLE entry(
entry_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
entry_type INT(11) NOT NULL,
entry_date DATETIME DEFAULT NULL,
entry_url VARCHAR(255) NOT NULL,
entry_photo VARCHAR(255) DEFAULT NULL,
entry_name VARCHAR(255) DEFAULT NULL,
entry_content TEXT DEFAULT NULL,
entry_desc TEXT DEFAULT NULL,
entry_t TEXT DEFAULT NULL,
entry_k TEXT DEFAULT NULL,
entry_d TEXT DEFAULT NULL,
entry_category INT(11) UNSIGNED NOT NULL,
PRIMARY KEY (entry_id)
)
ENGINE = MYISAM


error:


Error Number: 1052
Column 'entry_type' in where clause is ambiguous
SELECT `entry`.*, j2fdce1dc.entry_name AS s2fdce1dc, `entry`.entry_name AS 'entry.entry_name' FROM (`entry`) LEFT JOIN `entry` as j2fdce1dc ON `j2fdce1dc`.`entry_id` = `entry`.`entry_category` WHERE `entry_type` = 8
Filename: \www\system\database\DB_driver.php
Line Number: 330


version gCRUD 1.3.1

saulimus

saulimus
  • profile picture
  • Member

Posted 15 September 2012 - 15:11 PM

My guess is that it doesn't work because you cannot set a relation that points a table column to another column in the same table...

Akylenok

Akylenok
  • profile picture
  • Member

Posted 15 September 2012 - 15:34 PM

[quote name='saulimus' timestamp='1347721917' post='3445']
My guess is that it doesn't work because you cannot set a relation that points a table column to another column in the same table...
[/quote]

--- EN
why? have a field entry_category integer type and write back the id of the same table but the other entries (the so-called inheritance or the theory of adjacent vertices) I have already been used in version 1.3 but without the $crud->of the where clause. If we look at the text of the error you will see [b]WHERE clause `entry_type` = 8[/b] and MySQL путаетя of any table takes the `entry_type` must be written [b]WHERE clause [u]`entry`.[/u]`entry_type` = 8[/b]

--- RU
почему? имеем поле entry_category тип integer и пишем туда id этой же таблицы но другой записи (так называемое наследование или теория смежных вершин) я уже такое применял на версии 1.3 но без $crud->where. Если мы посмотрим на текст ошибки то увидим - WHERE `entry_type` = 8 и MySQL путаетя из какой таблицы берется поле `entry_type`, должно быть написано WHERE `entry`.`entry_type` = 8

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 15 September 2012 - 16:55 PM

Try this:

$crud->where( 'entry.entry_type', 8 );

Akylenok

Akylenok
  • profile picture
  • Member

Posted 15 September 2012 - 17:23 PM

[quote name='web-johnny' timestamp='1347728141' post='3447']
Try this:

$crud->where( 'entry.entry_type', 8 );

[/quote]

yes it's work, thx :)