⚠ 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

Not unique table/alias:



sitrakarivelo

sitrakarivelo
  • profile picture
  • Member

Posted 19 December 2014 - 14:59 PM

My own controller:

$crud = new grocery_CRUD();
            $crud->set_theme('mix');
            $crud->set_table('rhp_contrat_travail');
             $crud->set_model('carriere_model');
            $crud->display_as('dep_id','Département')
                ->display_as('pst_id','Poste')
                ->display_as('sal_id','Salarié')
                ->display_as('cat_id','Catégorie');
            $crud->set_relation('pst_id','rhp_poste','pst_nom');
            $crud->unset_print();
            $crud->unset_export();
            $crud->unset_edit();
            $crud->unset_delete();
            $output = $crud->render();
            $this->_example_output($output);

 

My own model:
 

 public function get_list() {
         $query=$this->_database->query('SELECT s.*, tmp.* FROM rhp_salarie as s  
         LEFT JOIN ( SELECT *, MAX(historisation) AS derniere_date FROM rhp_contrat_travail GROUP BY sal_id )
            tmp ON tmp.sal_id = s.sal_id
         WHERE tmp.sal_id  IS NOT NULL ORDER BY s.sal_id ');         
        
        $results_array=$query->result();
        return $results_array;    
        }

 

Why do I have this?  (repeated twice)

SELECT * FROM (`rhp_contrat_travail`) LEFT JOIN `rhp_poste` as ja8eccde7 ON `ja8eccde7`.`pst_id` = `rhp_contrat_travail`.`pst_id` LEFT JOIN `rhp_poste` as ja8eccde7 ON `ja8eccde7`.`pst_id` = `rhp_contrat_travail`.`pst_id`

Please give me a quick help

 

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 20 December 2014 - 02:59 AM

it is because u already having the same effect in the query .. and u also setting relation

 $crud->set_relation('pst_id','rhp_poste','pst_nom');

stop setting relation and it will not do the double left join. Either do the relation... or include in yr custom query


sitrakarivelo

sitrakarivelo
  • profile picture
  • Member

Posted 22 December 2014 - 05:10 AM

thanks for your quick response. Another problem when i set the relation into the query: my controller need this line $crud->set_table('rhp_contrat_travail'); and after that only the field of 'rhp_contrat_travail' appear, the others culomns I ask in my query did not appear. How can I specify more table in the set_table or make all the fields appeared?
sorry for my poor english.


sitrakarivelo

sitrakarivelo
  • profile picture
  • Member

Posted 22 December 2014 - 06:01 AM

Goal: I wanna put all the relation in my query:
I explain you in an other way my problem: i can't delete the line $crud->set_table('rhp_contrat_travail'); and as I know  I can't set more than on table in this line. So the fact is that grocery crud ignore the others tables I have in my query, their fields don't appear.

my query is:
$query=$this->_database->query('SELECT s.*, tmp.*, pst.* FROM rhp_salarie as s  
         LEFT JOIN ( SELECT *, MAX(historisation) AS derniere_date FROM rhp_contrat_travail GROUP BY sal_id )
            tmp ON tmp.sal_id = s.sal_id

         LEFT JOIN rhp_poste as pst ON pst.pst_id = tmp.pst_id
         WHERE tmp.sal_id  IS NOT NULL ORDER BY s.sal_id ');


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 22 December 2014 - 13:20 PM

Well frankly - i am not in much of position to deal in with custom query - i have not been using much of it. But 1 thing i can suggest you - since this is single field you wana present, i can recommend you to use a callback for the same. i know it will query up 25 more queries for the display but i think its bareable !