⚠ 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 problem with duplicate field name in 1.2.3



sstefanov
  • profile picture
  • Member

Posted 19 June 2012 - 13:20 PM

Hi,

I think I just hit a bug in 1.2.3 which did not exist in 1.2. The bug is duplicatable with CodeIgniter 2.1.0 and 2.1.1.

The problem is when I would like to use set_relation between a primary and secondary table and the field names in the primary and secondary tables are the same. In this situation the filed in the primary table (in the example racks.name) shows nothing in the gridview. In edit or add view everything is Ok. If the field names are not the same - everything is ok.

Here is the schema:

table racks:
[font=courier new,courier,monospace]CREATE TABLE IF NOT EXISTS `racks` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`room_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=170 ;[/font]

table rooms:
[font=courier new,courier,monospace]CREATE TABLE IF NOT EXISTS `rooms` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;[/font]

Here is the the php code:

function test() {
$this->_init_session();
$crud = new grocery_crud();
$crud->set_theme("datatables");
$crud->set_theme("flexigrid");
$crud->set_table("racks");
$crud->set_relation('room_id','rooms','name');
$crud->columns('name','room_id');
$crud->display_as('name','Rack Name');
$crud->display_as('room_id','Room');
$crud->set_subject("Rack",true);
$crud->order_by('id');
$output = $crud->render();
$this->_example_output($output);
}



Many thanks in advance for your help!

Regards,
Stefan

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

Posted 19 June 2012 - 21:43 PM

I am sorry but I cannot reproduce the error. For me it works fine. I tested it at grocery CRUD version 1.2.3 and Codeigniter 2.1.1 . [attachment=202:Untitled-1.png]

Just to make sure please download again the grocery CRUD version 1.2.3 and add all the files at your project and not only the library and the model and try again. If you still have the same problem can you please attach a print-screen of your steps and how the list looks likes?

sstefanov
  • profile picture
  • Member

Posted 20 June 2012 - 06:57 AM

Thanks for your quick reply. I just installed everything fresh (CI 2.1.1, groceryCRUD 1.2.3), freshly configured it and copied my files over - but again I can reproduce it. Attached are screenshots with Chrome and Firefox. The same happens with both Firefox and Chrome, and with Firefox there is even some artefact of rendering the table.

Here is the actual database I am using (in my example in the first post, I used a simplified tables):

[font=courier new,courier,monospace]--[/font]
[font=courier new,courier,monospace]-- Table structure for table `racks`
--

CREATE TABLE IF NOT EXISTS `racks` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`room_id` int(11) NOT NULL,
`customer_id` int(11) NOT NULL,
`key_id` int(11) NOT NULL,
`size_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=170 ;[/font]


[font=courier new,courier,monospace]--
-- Table structure for table `rooms`
--

CREATE TABLE IF NOT EXISTS `rooms` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;[/font]



And this is the code:

[font=courier new,courier,monospace]

function test() {
$this->_init_session();
$crud = new grocery_crud();
$crud->set_theme("datatables");
$crud->set_theme("flexigrid");
$crud->set_table("racks");
$crud->set_relation('room_id','rooms','name');
$crud->columns('name','room_id');
$crud->display_as('name','Rack Name');
$crud->display_as('room_id','Room');
$crud->set_subject("Rack",true);
$crud->order_by('id');
$output = $crud->render();
$this->_example_output($output);
}

function _example_output($output = null) {
$this->load->view('admin.php',$output);
}


[/font]

sstefanov
  • profile picture
  • Member

Posted 20 June 2012 - 08:22 AM

I found a workaround, but still I cannot understand what is going on. If I put the secondary table display field (set_relation third parameter) inside {}, then all is well. This code works:

function test() {
$this->_init_session();
$crud = new grocery_crud();
$crud->set_theme("datatables");
$crud->set_theme("flexigrid");
$crud->set_table("racks");
$crud->set_relation('room_id','rooms','{name}');
$crud->columns('name','room_id');
$crud->display_as('name','Rack Name');
$crud->display_as('room_id','Room');
$crud->set_subject("Rack",true);
$crud->order_by('id');
$output = $crud->render();
$this->_example_output($output);
}


PS: The Firefox rendering issue was my bug, sorry for the noise.

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

Posted 21 June 2012 - 06:43 AM

I am sorry I cannot understand why it doens't work for you <_< Can you please tell me: ubuntu version, PHP version , Mysql version and Apache?

sstefanov
  • profile picture
  • Member

Posted 21 June 2012 - 23:08 PM

Ubuntu 10.04.4 LTS, Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.17 with Suhosin-Patch

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

Posted 24 June 2012 - 12:40 PM

Still I cannot reproduce the error, but I will check it further. Perhaps it has something to do related with this issue: https://github.com/scoumbourdis/grocery-crud/issues/68

Thanks

sstefanov
  • profile picture
  • Member

Posted 30 August 2012 - 10:24 AM

Just to let you know, that version 1.3 does not seem to suffer from this issue. Or it may be the careful installation of 1.3 that solved it.

Stefan

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

Posted 31 August 2012 - 06:26 AM

Yeap this problem is fixed as for version 1.3 https://github.com/scoumbourdis/grocery-crud/issues/68