John Siracusa wrote on 2/1/08 4:50 PM:
> On Feb 1, 2008 4:49 PM, Sam Tregar <[EMAIL PROTECTED]> wrote:
>> But without the reload subscribed_lists() keeps returning the old list. Is
>> there a way to tip off Rose that any cached lists for a particular
>> relationship are stale? Or something I'm doing wrong?
>
> All get_set* relationship accessors will will only fetch the related
> object(s) from the db once, after which they will just return what
> they've previously fetched. (The docs need to be more clear about
> this, I think.) This is considered a feature :)
>
> To make an object forget a previously fetched set, just set it to undef:
>
> @lists = $user->subscribed_lists(); # get list
> ... # modify list in the db
> $user->subscribed_lists(undef); # forget old list
> @lists = $user->subscribed_lists(); # get new list
>
> Note that this is very different from passing an empty list ([]),
> which says "replace the existing set of rows in the database with this
> new (empty, in this case) list." That's not what you want :)
>
Wonder if something like this would make a useful Helper:
sub forget {
my $self = shift;
my $accessor = shift or croak "need accessor name";
$self->$accessor( undef );
}
So you could say:
$user->forget('subscribed_lists');
and avoid causing yourself (or your co-workers) anxiety later when looking at:
$user->subscribed_lists( undef );
and wondering why you were 'deleting' all the lists.
The nuance of passing [] vs undef just seems like an API feature that is easy
to
...um... forget, and non-intuitive to the programmer looking at existing code.
Just a thought.
--
Peter Karman . http://peknet.com/ . [EMAIL PROTECTED]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object