|
From: Chris W. <ch...@cw...> - 2004-12-01 19:22:17
|
> ...
> But you'll have to change code anyway if you switch from auto/lazy to
> manual if you have any code that accesses the book object (since it
> will no longer be auto/lazy-fetched). I view the specification of the
> auto/lazy vs manual as part of specifying the 'type' of the field. If
> you change the 'type' you should expect to have to change code in order
> to get at the same data (e.g. the id).
>
> If I understand your proposal you would always have the field hold the
> id and have it store the auto/lazy-fetched object into some other key
> in the parent object? What key? This approach requires you to specify
> for each auto/lazy fetched field another name by which you access the
> object. You have to worry about inconsistency between the id and the
> object. When you go to save, if the id in the field doesn't match the
> id of the object in corresponding key, which do you save?
>
> I just think it is simpler and more straightforward to use the single
> field and think of the auto/lazy vs manual as part of the type
> definition for that field.
> ...
>
> OK, I think I understand your point. IF you use separate field names
> for the id (persistent field) and the auto/lazy-fetched object (temp
> non-persistent field), I suppose there is no need for manual fetch.
>
> But if you use the same field for the id and the auto-fetched object,
> then you DO need the manual option. I still think this is a cleaner
> approach since you're not cluttering up your object with extra fields
> unnecessarily and it allows you treat some fields as ids (manual) and
> others as objects (auto/lazy), which I find useful conceptually.
Just to be clear what we're talking about here:
book:
book_id, title, publisher_id
publisher:
publisher_id, name
book_author:
book_id, author_id
author:
author_id, name
Book 1 ---> 1 Publisher
Book 1 ---> * Author
my $book = Book->fetch(42);
$book->publisher == object (whether manual/lazy fetch)
$book->publisher_id == ID
$book->author == list of objects (whether manual/lazy fetch)
Is that right? Because it sounds from the discussion as if:
$book->publisher == sometimes ID, sometimes object,
depending on the configuration
which IMO is very confusing.
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|