RE: Can we have one SQL query producing two CDBI classes

[prev] [thread] [next] [Date index for 2005/04/21]

From: Perrin Harkins
Subject: RE: Can we have one SQL query producing two CDBI classes
Date: 20:49 on 21 Apr 2005
On Thu, 2005-04-21 at 19:52 +0100, Ian McDonald-ONLINE wrote:
> I found this in the list archives. Any more input from someone who has
> tried to do this, on how robust this is, or how to involve
> not-really-a-cache, would be appreciated.

I don't think there's any problem with the object index and construct(),
as shown below.  The cache issue discussed here is that when you call a
has_many() method, it will try to fetch from the database, even if the
objects have been loaded already.  This is because has_many() is
stateless, and doesn't keep track of objects that were loaded with it.
(The has_a() method actually does keep a ref to the object it loaded, so
you have to fill that in if you use this approach.)

Implementing a real cache would prevent the objects from being fetched
again via has_many(), although avoiding doing the initial query to find
their IDs would be harder.

None of this should be an issue for you, because your example is loading
objects that have a 1-1 relationship, right?  So, I think what you did
would work (provided the tables don't have overlapping column names),
except that you can't read the same $sth twice like that without
executing it again.

- Perrin

Can we have one SQL query producing two CDBI classes
Ian McDonald-ONLINE 18:34 on 21 Apr 2005

RE: Can we have one SQL query producing two CDBI classes
Ian McDonald-ONLINE 18:52 on 21 Apr 2005

RE: Can we have one SQL query producing two CDBI classes
Perrin Harkins 20:49 on 21 Apr 2005

Generated at 09:29 on 27 Apr 2005 by mariachi v0.52