On Jan 9, 2008 2:05 PM, Curon Davies <[EMAIL PROTECTED]> wrote:
> The file works fine if the User (in this case 'rose_test') has DELETE
> permission the on 'price' table, but fails otherwise. From my
> prospective this should definitely not be the case, as the only action
> performed here is inserting into the database. Of course, I could call
> the insert method, but that defeats the point of having a common save
> method.

In your test, you are setting the "prices" one-to-many collection:

$product = My::DB::Product->new(
  name => $^T,
  prices =>
  [
    { price => 3.60, region => 'uk' },
    { price => 7.00, region => 'us' },
  ]);

$product->save;

Setting the collection means replacing the existing contents (if any)
with the new contents.  So the queries actually run are a DELETE and
then a series of INSERTs.

Now in this case you may "know" that this is a new record, but the
code does the same thing regardless.  This is mostly done as a
safeguard or guarantee that setting a collection always really sets a
collection's entire contents.

Arguably, a feature could be added that would let the programmer
specify that these objects are not expected to already be in the db,
so don't bother with the DELETE before setting the collection.  Maybe
save(insert_only => 1) or something?  Maybe others have better ideas?

In the meantime, you can always express more explicitly the operations
you intend to perform.  For example:

$product = My::DB::Product->new(
  name => $^T,
  add_prices =>
  [
    { price => 3.60, region => 'uk' },
    { price => 7.00, region => 'us' },
  ]);

$product->save;

There should be no DELETE queries issued for that, though it may look
a bit odd to be "adding" to a collection that you expect to be empty
to start with (although that seems valid to me).  A comment before
such a block could explain this, perhaps.

-John

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to