⚠ 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

Set Relation (dropdown to show only available products)


  • profile picture
  • Member

Posted 19 November 2020 - 18:04 PM

Hey guys! I am using Grocery Crud Enterprise with Code igniter 3.


I have two Tables. 

Table 1= Rentals (Rental_id, Product_id, Rental_type, Start_Date, End_Date)

Table 2= Products (Product_id, Product_name)


I am using  $crud->setRelation('product_id','products','product_name'); so where I add a new rental there is a dropdown, so I can choose a product.


My problem is that I would like to find a way, to be able to see only the "available" products in this dropdown.


I have created a view= Available_Products, where I can see in a third table only the available products.


Where I use 




I can see all the rentals in the table, and only the available products in the dropdown list, but when I click +Add Rental, there is an error. (Maybe because it is a view, and not a table)



is there a way to fix it? or an other way to make it work?


Thanks in advance, please save me ! :)






  • profile picture
  • Member

Posted 19 November 2020 - 20:28 PM



You can use 4th parameter with where condition:


$crud->setRelation('product_id','products','product_name', ['available' => 'yes']); 


Check documentation:





  • profile picture
  • Member

Posted 21 November 2020 - 19:04 PM

Hi marceloje,


Thanks for your answer! It was quite helpful. :)