⚠ 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

[SOLVED] Is it possible to have a where clause on setRelationship?



Graham

Graham
  • profile picture
  • Member

Posted 17 April 2017 - 17:45 PM

Would it be possible to have a where clause on setRelationship?

 

Thanks


darkstalker

darkstalker
  • profile picture
  • Member

Posted 18 April 2017 - 11:02 AM

yes, you can.

 

you need to use this syntax :

 

$crud->setRelation('customer_id','customers','{lastname} {firstname}',['customers.city = ?' => '%Toronto%']);

 

you can use = , > , < or even LIKE statement. Check this other example:

 

$crud->setRelation('customer_id','customers','{lastname} {firstname}',['customers.city LIKE ?' => '%New%']);

 

The first example show lastname and firstname instead of the customer_id field. Only the customers in the city of Toronto shows up.

 

The second example is similar but you accept every customer with the word "New" in the city field. Example: New York, New Orleans.....

 

Hope this examples help you understand. Bye


web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 10 July 2017 - 04:15 AM

I think @darkstalker covered my answer :)

One more thing to have in mind is that unlike the community edition, Grocery CRUD Enterprise is coming with extra where parameters for security. So for example in case you are having only the setRelation with where then the user can't see any other entries even if the user will try to hack it!

 

If you guys need more documentation about the extra security implementations of GCE let me know.

 

Thanks

Johnny