⚠ 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. ⚠

Set Relation (dropdown to show only available products)

  • Please log in to reply
2 replies to this topic

#1 dmanolias



  • Members
  • Pip
  • 5 posts

Posted 19 November 2020 - 06: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 ! :)





#2 marceloje



  • Members
  • Pip
  • 2 posts

Posted 19 November 2020 - 08:28 PM



You can use 4th parameter with where condition:


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


Check documentation:




#3 dmanolias



  • Members
  • Pip
  • 5 posts

Posted 21 November 2020 - 07:04 PM

Hi marceloje,


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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users