⚠ 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

Invoice line items, n-n relation, and item quantity



medkhai
  • profile picture
  • Member

Posted 04 July 2012 - 19:29 PM

I am trying to make a simple database to keep track of customer orders.

I have all the usual suspects as tables: Customers, Orders, Products
I have then used a table to make an n-n relationship between orders and products: OrdersProducts

[b]Customers:[/b]
CustomerID, CustomerName

[b]Orders:[/b]
OrderID, CustomerID, OrderDate

[b]Products:[/b]
ProductID, ProductsName, ProductPrice

[b]OrdersProducts:[/b]
OrderID, ProductID, Quantity


Finally here's my code:

[font=courier new,courier,monospace]function Orders()[/font]
[font=courier new,courier,monospace]{[/font]
[font=courier new,courier,monospace]$crud = new grocery_CRUD();[/font]
[font=courier new,courier,monospace]$crud->set_table('Orders');[/font]
[font=courier new,courier,monospace]$crud->set_subject('Order');[/font]
[font=courier new,courier,monospace]$crud->set_relation_n_n('Products', 'OrdersProducts', 'Products', 'OrderID', 'ProductID', 'ProductName');[/font]
[font=courier new,courier,monospace]$output = $crud->render();[/font]
[font=courier new,courier,monospace]$this->_mgm_output($output);[/font]
[font=courier new,courier,monospace]} [/font]

It works fine and I can add Products to Orders.

However I also need to be able to set the quantity of each Product for this order when I add them.... how can this be done?

Thank you

brunohauck
  • profile picture
  • Member

Posted 19 January 2013 - 19:31 PM

I have the same problem. I'm trying to set n n relationship but I can't set the quantity.

goFrendiAsgard
  • profile picture
  • Member

Posted 20 January 2013 - 15:30 PM

You can't. The solution is by making your own code via "callback_field".
http://www.grocerycrud.com/documentation/options_functions/callback_field
It gonna be a hard-work though :(

You might probably want set_relation_1_n if it is exists. But since it is not, you might be interested on this:
/topic/1260-no-cms-and-grocery-crud-master-detail-form/#entry5168
You will still need some custom code, but I hope it can reduce your pain :)