On 2/6/07, Derek Watson <[EMAIL PROTECTED]> wrote:
> How would I go about deleting only the UK price? The following seems to
> delete the UK price record, but leaves it in the collection of $p->prices.
>
> my ($price) = grep { $_->region eq 'UK' } $p->prices;
> $price->delete;

After doing that, you could set prices to undef to cause the
collection to be re-fetched from the database on the next access:

    my($price) = grep { $_->region eq 'UK' } $p->prices;
    $price->delete;
    $p->prices(undef);    # forget previously fetched collection
    @prices = $p->prices; # collection no longer contains deleted entry

> Should I also be calling $p->save? Or should I be doing something more like
> this?
>
> my @prices = grep { $_->region ne 'UK' } $p->prices;
> $p->prices(@prices);
> $p->save;

That works too, but it's quite inefficient, deleting and re-inserting
the entire price list (now sans one price) on save().

> Is there a more explicit way to do what I'm after without resorting to this
> grep business?

Both of those techniques seem pretty explicit to me :)  I'm not sure
what more could be done without delving into some extra magic, e.g.
making each price aware of what collection it was fetched as part of
so that $price->delete will also cause it to be removed from the list.
 But magic like that it a lot more trouble than it's worth, IMO.
(It's not hard to think of scenarios where that magic would break.)

If you do this a lot, it shouldn't be too much trouble to make a
helper method to hide the details of the implementation.

> I remember talk a couple weeks back about $p->find_prices(region => 'UK')
> functionality.  Will this be included in a release sometime soon?

Yes, probably by the end of the month at the latest.  It's in SVN now
if you want to try it.

-John

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to