Jump to content


Add View as relation to Table ( $crud->set_relation('bTabField', 'rView', 'relField') )

view set_relation

  • Please log in to reply
1 reply to this topic

#1 spezialista

spezialista

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 23 November 2017 - 04:14 PM

Hello,

 

I have found some topics about using view in grocery crud but nothing answering my problem so maybe members here can help?

 

this is my setup

 

$crud = new grocery_CRUD();
$crud->set_model('custom_CRUD_Model'); //this is for other reasons
$crud->set_table('MEMBER');
$crud->set_theme('datatables');
$crud->set_language('german');
$crud->set_subject('Benutzer'); //means user
 
$crud->set_primary_key('ID', 'MEM2OFFICEVIEW');
$crud->set_relation('ID', 'MEM2OFFICEVIEW', 'OFFICE');
 
$output = $crud->render();
$this->user_manager_output($output);
 
but nothing happens with that relation -> no error but also no additional column in grid
 
The JOIN should be
 
'MEMBER'.'ID' = 'MEM2OFFICEVIEW'.'ID' and the additional column should be 'OFFICE' for the office_name, but nothing there...
 
Here View-create 
 
CREATE 
    ALGORITHM = UNDEFINED 
    DEFINER = `user`@`%.%.%` 
    SQL SECURITY DEFINER
VIEW `MEM2OFFICEVIEW` AS
    SELECT 
        `OFFICE2MEMBER`.`MEMBER_ID` AS `ID`,
        `OFFICE`.`OFFICE_ID` AS `OFFICE_ID`,
        `OFFICE`.`OFFICE` AS `OFFICE`
    FROM
        (`OFFICE2MEMBER` JOIN `OFFICE` ON `OFFICE2MEMBER`.`OFFICE_ID` = `OFFICE`.`OFFICE_ID`)

 

 

 
 
Am I doing something wrong? Please Help!
 
 

 



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 23 November 2017 - 04:40 PM

Well.. if i am not mistakened, you have created a member table with ID as primary key

and the same ID you are using in mem2officeview

 

i dont really see a good reason to slit the table data unnecessarily .. but anyways, its your call.

Very 1 thing, GC dose not pick up the primary key as a column 2 be displayed. Hence, it will not pickup ID by itself.

If you want to show it, you need to exclusilvely set that in the columns listing.

 

Post that - i dont really see a good reason for you to have set the primiarykey for mem2officeview.. even without it - the relation will happen fine

Now - you want to display office_name and you selecting field OFFICE in the relation - how can it technically work. 

 

Please refer to the document and work around - what you intending to do is  - show office_name for ID and set the column title as OFFICE - that is done with display_as

 

Refering to the document will surely help you understand the system better and will be in good position to use the library much better.

 

Happy GCing :)







Also tagged with one or more of these keywords: view, set_relation

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users