⚠ 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

Using set_relation to do simple 1 table JOIN, results always NULL



Alex A

Alex A
  • profile picture
  • Member

Posted 30 June 2015 - 12:35 PM

Hello, I am having trouble joining two tables. Seems like the join works just fine but at the results table the content is always empty:

fJsyCAR.jpg

A look from the Edit: 

O2rmRSV.jpg

Even if i select manually and save still nothing changes on the table.

This is my code:

    public function reservations() {
        
        
        $crud = new grocery_CRUD();
        
		$crud->set_theme('bootstrap');
        $crud->set_table('reservations');
        $crud->set_subject('Reservation');

        
        $crud->columns('RES_ID', 'PROP_NAME', 'RES_CHECK_IN', 'RES_CHECK_OUT', 'RES_N_ADULTS', 'RES_GUEST_FIRSTNAME', 'RES_GUEST_LASTNAME', 'BOOKING_SOURCE_ID', 'DATE_ADDED', 'IS_TRANSFER', 'IS_ARRIVED');
        
        
        
        
         $crud->display_as('RES_ID','RES ID');
         $crud->display_as('PROP_ID','PROP NAME');
         $crud->display_as('RES_CHECK_IN','CHECKIN');
         $crud->display_as('RES_CHECK_OUT','CHECKOUT');
         $crud->display_as('RES_N_ADULTS','GUESTS');
         $crud->display_as('RES_GUEST_FIRSTNAME','FIRST NAME');
         $crud->display_as('RES_GUEST_LASTNAME','LAST NAME');
         $crud->display_as('BOOKING_SOURCE_ID','SOURCE');
         $crud->display_as('IS_TRANSFER','TRANSFER?');
         $crud->display_as('IS_ARRIVED','ARRIVED?');
        
         $crud->set_relation('PROP_ID', 'properties', 'PROP_NAME');
         $crud->set_relation('BOOKING_SOURCE_ID', 'listBookingSources', 'BOOKING_SOURCE_LABEL');

        
        $output = $crud->render();
        $this->_example_output($output);  
        
        			return $output;

    }

A look from the tables:

d1JZ0LF.jpgosYc1Up.jpg

Thanks!

 


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 01 July 2015 - 12:40 PM

Hi!

$crud->set_relation('PROP_ID', 'properties', 'PROP_NAME');
 

 

Here you relation above, have look like "JOIN properties ON properties.id = reservations.PROP_ID" - this is why GC relate table by default name of primary key - "id"

But you need to "JOIN properties ON properties.PROD_ID = reservations.PROP_ID".

More is here http://www.grocerycrud.com/documentation/options_functions/set_primary_key


Alex A

Alex A
  • profile picture
  • Member

Posted 01 July 2015 - 15:53 PM

Hi!

$crud->set_relation('PROP_ID', 'properties', 'PROP_NAME');
 

 

Here you relation above, have look like "JOIN properties ON properties.id = reservations.PROP_ID" - this is why GC relate table by default name of primary key - "id"

But you need to "JOIN properties ON properties.PROD_ID = reservations.PROP_ID".

More is here http://www.grocerycrud.com/documentation/options_functions/set_primary_key

 

Hi!

 

Thanks for the save! got it working .. Was not thinking about Primary Key! Thanks alot..


        $crud = new grocery_CRUD();

        $crud->set_theme('bootstrap');

        $crud->set_table('reservations');
        $crud->set_subject('Reservations');
        $crud->set_primary_key('PROP_ID','properties');
        $crud->set_relation('PROP_ID','properties','PROP_NAME');

        $output = $crud->render();

        $this->_example_output($output);


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 01 July 2015 - 19:27 PM

You're welcome!