⚠ 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 forum is read-only and soon will be archived. ⚠

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



  • Members
  • Pip
  • 2 posts

Posted 23 November 2017 - 04:14 PM



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_subject('Benutzer'); //means user
$crud->set_primary_key('ID', 'MEM2OFFICEVIEW');
$crud->set_relation('ID', 'MEM2OFFICEVIEW', 'OFFICE');
$output = $crud->render();
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 
    DEFINER = `user`@`%.%.%` 



Am I doing something wrong? Please Help!


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts

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 :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users