Not sure if I’m doing this correctly - I’m trying to create a Product ordering system via a CGridView. The grid is displayed for the Product table.
Now what I plan to do is have a dropdown on each row in my CGridView which allows me to select the quantity required of a product. Upon selecting a quantity, an ajax request is made that inserts a record in the ‘Basket’ table with the product_id and quantity of the product.
Now for this to work properly, the quantity field in my CGridView will need to fetch the quantity value for any products that have a record in the ‘Basket’ table. This is where I’m struggling at the moment. I created the following relation in my ‘Product’ model:
I am not sure if I understood your problem, but I am guessing you have to pass a fourth parameter with htmlOptions and an options array inside. The best way is probably to create one more method which would check for your condition and return array(‘options’ => array($default_value => array(‘selected’=>‘selected’))) or an empty array otherwise.
This is probably easier than it seems, so I will try and resolve this from the start - can you advise whether the relation I have created is correct for what I am trying to do (and in the correct model)? I have never used HAS_ONE relation type before but it was the only one that (half) works for me in this instance.
Cheers tri. Now I have tried to understand your previous comment, where you say "pass it ($data, "dummy_quantity") to the activeDropDownList.
The problem is not about specifying the "dummy_quantity" - but the fact that $data (or $model in my case) is null. This is because if the product_id does not exist in the Basket table then it returns null.