On Jul 7, 2:01 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Jul 7, 2010, at 1:53 PM, Lance Edgar wrote:
>
>
>
> > OMichael, thanks for the tip.  I still found this somewhat confusing
> > though:
>
> > When my code runs, the mapper has already been created (and
> > "compiled", I assume).  So what I ended up doing, that seemed to work,
> > is:
>
> > class_mapper(Order).add_property('quantity',
> > column_property(cast(orders.c.quantity, Integer)))
>
> > The thing is, the mapper *already* had a "quantity" property so
> > without knowing the internals of that business I can only assume that
> > my .add_property() call doesn't have weird side effects (although it
> > does accomplish what I'm after).  The mapper exposes .get_property()
> > and .iterate_properties(), and of course .add_property(), but I guess
> > I would have expected there to be a .set_property()
> > or .update_property().  Is this just a quirk in the wording or my
> > understanding, or am I still missing some important step?
>
> It's add_property() since you are adding a new property to the existing 
> collection of properties.   It is not really intended for the "replacement" 
> of existing properties as that has direct impact on the instrumentation of 
> the mapped class.   It probably works in the simple case here, but would be 
> better if you were to define it "inline" with the original Order mapper.

Well, I'm already seeing some issue(s) with it even in my simple
case.  Where this used to return an Integer-type Column...

class_mapper(Order).get_property('quantity').columns[0]

...now it returns a sqlalchemy.sql.expression._Label object.  This
makes sense because of the "SELECT CAST(...) AS anon_1" that's
happening at the SQL level, but it's throwing FormAlchemy off in this
case and I guess generally speaking I hoped for a more transparent
override.  So my follow-up question is:  Is there a way to tear down
and replace the mapper for just a single class, or is the only
relevant option the clear_mappers() function which will remove all
class mappings?  If I can't replace a single property within the
mapper then I'm ok with replacing the mapper, but replacing all of
them seems a bit heavy-handed.

Lance

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

Reply via email to