Hi Mike,
   No, Rick's method didn't work for me... I've defined attributes
using assign_mapper, and those don't seem to be in place when I need
them.  It's fine for me doing this in Python after getting everything
back from SA, and in fact perhaps it is easier, coding-wise.  But I
got all excited trying my own MapperExtension and other approaches and
was let down when it didn't work the way I thought it might.  In my
little MCV world, it's part
of M, not C or V and I wanted to keep it that way as much as
possible.  It still is, just not in SA.
   So to answer your other question, sure I can wait (ha!) for 0.4...
if it helps me then, I'll recode for it.  I'm mostly an eager loader
here, bundling up all my various parts into nice objects that have all
the attributes they need all in one place, easily accessed by the
Controller and View.  So I'm not too worried about the lazy part of
this.
  Thanks a bunch.  SA is great, btw.  I heard about it back in Zope2/
Plone days, but it was off in the distance, something the Zope3 crowd
was playing with, and I didn't pay too much attention.  But I like it
now that I have need for it (no ZODB in Turbogears).  Cheers.
Paul


On Jul 14, 2:16 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> hi paul -
>
> Im not entirely opposed to an additional hook,however this is a per-
> object hook which means we are adding method call overhead to each
> individual object loaded, which is why im hesitant.  does the
> approach that Rick outlined in his email work ?
>
> i.e.
>
> def populate_instance(self, mapper, selectcontext, row, instance,
> identitykey, isnew):
>       mapper.populate_instance(selectcontext, row, instance,
> identitykey, isnew)
>       if isnew:
>             YOUR CODE HERE
>       return None
>
> in the above approach, all attributes on the instance are fully
> present.  however, eagerly-loaded collections may not be fully
> populated with their final results (and of course, lazily-populated
> collections will not be populated at all).  if the issue is that you
> are waiting for eagerly-loaded collections on the instance to be
> fully populated, or that you want to be able to fire off lazy
> collections, then the above is not as optimial;  populate_instance()
> is called repeatedly for each eagerly-loaded row (with the isnew flag
> set only the first time), and theres no indicator when the "last" row
> has been loaded...also there might be issues firing off lazy
> collections at this stage.
>
> So as far as that hook, we have a much better place for this hook in
> the 0.4 version of SQLAlchemy, since that version does include an
> official "post-load" step after all result rows have been exhausted.
> can you wait til then ? (the 0.4 checkout is available right now from
> its branch).  also let me know if firing off lazy collections is a
> requirement, as I will add additional unit tests to ensure that
> scenario works.
>
> On Jul 14, 2007, at 12:27 PM, Paul Howell wrote:
>
>
>
> > I've gotten a long way with using SA in Turbogears, but I want one
> > more thing (for now).
>
> > In short, I want to attach some properties to the Data objects after
> > everything else has been done.  I could do this in my Python code
> > AFTER my select() results are returned (I do that now), but would
> > rather do that in a MapperExtension.  I want/need to do it at the very
> > end because I want the objects to have all their mapper-added
> > attributes added on to them, so that I can reference them in the
> > creation of these attributes.  This would be MUCH easier than digging
> > deeper into the SQL joins and such to get the information from the
> > rows.
>
> > I tried using MapperExtension, append_results() (and everything else
> > in MapperExtension), but the attributes added in the mapper are not
> > there yet, even in append_results, which seems to be the last thing
> > called.
>
> > I think this feature/concept was what Rick Morrison was referring to
> > when he tried to "bump" Mike Bayer about "after" hooks here (
> >http://groups.google.com/group/sqlalchemy/browse_thread/thread/
> > 912c8f55f483069b/4bdc2c8320b8cac1?lnk=gst&q=MapperExtension
> > +bump&rnum=1#4bdc2c8320b8cac1
> > ) back in February.
>
> > Any ideas?
> > Paul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to