⚠ 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

Can get set_relation to work



johanb
  • profile picture
  • Member

Posted 02 June 2020 - 14:33 PM

Hi

 

I'm trying to get an dropdown list via set_relation but can't get it to work.

 

CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `atest` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
)

CREATE TABLE `btest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `test_to_a` int(11) DEFAULT NULL,
  `asdf` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
)

 

 

        public function btest()
        {
                $crud = new grocery_CRUD();

                $crud->set_table('text');
                $crud->set_relation('test_to_a','test','id');

                $output = $this->grocery_crud->render();
                $this->_toutput($output);
        }

 

What am I missing here?

 

Johan
 

 

 


stepgr
  • profile picture
  • Member

Posted 03 June 2020 - 15:07 PM

I guess you have seen the typo :

  $crud->set_table('text');

??

 

also set_relation  needs (remote key, remote table, remote field) in your case you should :

 

set_table(btest)

set_relation("id","test","atest")

 

If I'm guessing right what you want to do .

 

 

EDIT:  since I saw it myself : it's not remote key is local key is set_relation so the correct is:

set_relation(local_key, remote_table, remote_filed(s))