Hey guys,
I’ve been thinking about how to properly handle the following situation: How to add related objects when the relation table has extra attributes?
I’m concerned about the presentation and user experience. Not the php code that actually saves the relation to the database.
As an example, take a look at following diagram.
In this case, we want to relate orders to products, but we have to specify the price and amount.
I thinking about creating a widget that adds the following section to a form
The user interaction happens as follow:
[list=1]
[*]The user types a product name
[*]A table pops down with live updated search results
[*]the user clicks on "Add" to attach the product to the Order
[*]The product goes to a permanent list where the user can modify other OrderItem’s attributes
[/list]
Once the form is submitted, you have a post param products[] which is an array indexed by the product_id and in which each element is an array with the fields price and amount.
A possible configuration options array would be:
array(
'model' => 'Order', // use full path if not autoloadable
'relation' => 'products', // as defined in the model's relations() method
'copy_fields' => array('price' => 'price'), // the price field value of the products table will be copied to the price text field
'readonly_fields' => array('price'), // makes the price text field read only
'hide_fields' => array(), // hide fields in the list of added products
'result_fields => array('name', 'price'), // which fields of product should appear on the search result list, defaults the first string field on the table
);
So, you may be wondering, “if its not done, why post here?”. Well, I’m new to Yii, so, maybe there are something like this around and I just couldn’t find it. And, if not, I want to discuss it first before getting my hands dirty.
[size="2"]If you have any comments, opinions or suggestions about this, please, SHARE IT!![/size]