Hi -

I've noticed weird behavior when dealing with "one-to-many" relation.
I'll use tutorial objects Product -> Vendor to describe it.

You can get all products for given vendor by calling
$vendor->products. I want to add one more product for this vendor, so
I do (pseudo-code):

   my @products = $vendor->products;
   push @products, Product->new();
   $vendor->products([EMAIL PROTECTED]);
   $vendor->save();

My initial surprise is that after calling save() the database table
for products contained only the new product I've created for this
vendor. After digging a little bit, I saw that when updating vendor,
it first deletes all products for this vendor and tries to add the new
ones. So far, so good. But all the objects retrieved using products()
method are in state "in_db" which means that they will be updated
(using SQL UPDATE) instead of INSERTed. Since thay are gone after
DELETE, the update silently fails. When I unset this state using 
RDBO::Util::unset_state_in_db, everything worked fine - all the
objects are inserted correctly, including the new one.

It seems the RDBO::Manager should unset the db state of objects passed
as one-to-many relation in order to force INSERT since it issues
DELETE first

Also I understood that my approach isn't very effective so I'll use
the many-to-one relation of Product object in order to add one more
product for given vendor:
   my $product = Product->new;
   $product->vendor($vendor); # $vendor ISA 'Vendor'
   $product->save();

--Svi
N�HS^�隊X���'���u��<�ڂ�.���y�"��*m�x%jx.j���^�קvƩ�X�jب�ȧ��m�ݚ�����v&��קv�^�+����j�Z����{az����^��h��஋�n���)��{h�����ا�׫�+h�(m�����Z��jY�w��ǥrg

Reply via email to