[sqlalchemy] Relationships with Concrete Inheritance with Abstract super class

2013-07-13 Thread Alexandre Torres
Hi again, I implemented a relationship using back_populates using the example http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#relationships-with-concrete-inheritance But I stumbled in a problem: My super class A does not have a table, it is based in a polymorphic union (thanks Michael

Re: [sqlalchemy] possible bug in InstrumentedAttribute.__delete__?

2013-07-13 Thread Lars van Gemerden
I think i didn't explain the error enough; just calling del user.name in the example below causes an exception (except when i already accessed (say print user.name) the attribute, which seemed odd to me). This is independent of whether the attr becomes None. Otherwise it isn't a real problem

Re: [sqlalchemy] Query compilation cost

2013-07-13 Thread Amir Elaguizy
Awesome Michael it has given a speedup actually outside of caching even, which is great. How do I do the equivelant of this though? compiled = stmt.compile() params = compiled.params # here we return the key as a long string. our key mangler # set up with the region will boil

[sqlalchemy] Re: Changing the declarative base of a class and re-mapping

2013-07-13 Thread Ahmed
It seems that I have found a solution. After digging in sqlalchemy code, it seems that the _configure_property mapper function would do the trick. so ... newprop = RelationshipProperty(newtargetmodel, **rel_kwargs) newparentmodel.__mapper__._configure_property(oldprop.key, newprop) so what I

Re: [sqlalchemy] Changing the declarative base of a class and re-mapping

2013-07-13 Thread Michael Bayer
On Jul 13, 2013, at 1:48 AM, Ahmed ahmedba...@gmail.com wrote: Hello all, I have the following scenario: I have 5 or 6 related sqlalchemy declarative models sitting in a pyramid app. This occurs in the context of extending a pyramid application, where I import/config.scan() these

Re: [sqlalchemy] Relationships with Concrete Inheritance with Abstract super class

2013-07-13 Thread Michael Bayer
On Jul 13, 2013, at 9:13 AM, Alexandre Torres alexandre.tor...@gmail.com wrote: Hi again, I implemented a relationship using back_populates using the example http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#relationships-with-concrete-inheritance But I stumbled in a problem: My

Re: [sqlalchemy] possible bug in InstrumentedAttribute.__delete__?

2013-07-13 Thread Michael Bayer
On Jul 13, 2013, at 10:24 AM, Lars van Gemerden l...@rational-it.com wrote: I think i didn't explain the error enough; just calling del user.name in the example below causes an exception (except when i already accessed (say print user.name) the attribute, which seemed odd to me). This is

Re: [sqlalchemy] Query compilation cost

2013-07-13 Thread Michael Bayer
On Jul 13, 2013, at 11:27 AM, Amir Elaguizy aelag...@gmail.com wrote: Awesome Michael it has given a speedup actually outside of caching even, which is great. How do I do the equivelant of this though? compiled = stmt.compile() params = compiled.params # here we return

[sqlalchemy] Re: Relationships with Concrete Inheritance with Abstract super class

2013-07-13 Thread Alexandre Torres
SQLAlchemy already understands that class A is abstract, and if it doesn't have the relationship that is also fine, but then there's nothing to point a back populates towards. If you want a back populates then you have to make the action relationship on your base class.This is

[sqlalchemy] Re: Relationships with Concrete Inheritance with Abstract super class

2013-07-13 Thread Alexandre Torres
actually it is not a list, because it is the one side, I just need to return None. alright? I just need to lure the orm for the abstract class A returning an empty list. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from

[sqlalchemy] Re: Relationships with Concrete Inheritance with Abstract super class

2013-07-13 Thread Alexandre Torres
Oh, it was so easy! XMapper = mapper(X, C_table, properties={ 'resources': relationship(A,collection_class=set,*back_populates='action'* )}) AMapper = mapper(A,pjoin,with_polymorphic=('*', pjoin),polymorphic_on=pjoin.c.type,properties={ 'action' : relationship(X) # no back_populates, it will

[sqlalchemy] Re: Relationships with Concrete Inheritance with Abstract super class

2013-07-13 Thread Alexandre Torres
Thank you again Michael! It is really awesome, I can just add to the resources collection and it will know what is the correct reverse action. Em sábado, 13 de julho de 2013 16h06min55s UTC-3, Alexandre Torres escreveu: Oh, it was so easy! XMapper = mapper(X, C_table, properties={

Re: [sqlalchemy] possible bug in InstrumentedAttribute.__delete__?

2013-07-13 Thread Lars van Gemerden
Just trying to help; i am not sure, but what you might also consider is to initialise attributes (or on first access) with a default if a default value as Column argument is given (i am already doing this in my own code) and also reset to this default in case of del, but maybe there are

Re: [sqlalchemy] The cost of defer()

2013-07-13 Thread Michael Bayer
anyway, with some profiling of loading 1000 rows with six deferred cols, the function count with the defer was over 50K and without the defer around 37K; the patch is now committed and with the defer it's at 32K, so a bit less than that of loading the data, as it should be (more would be better

Re: [sqlalchemy] possible bug in InstrumentedAttribute.__delete__?

2013-07-13 Thread Michael Bayer
On Jul 13, 2013, at 3:21 PM, Lars van Gemerden l...@rational-it.com wrote: Just trying to help; i am not sure, but what you might also consider is to initialise attributes (or on first access) with a default if a default value as Column argument is given (i am already doing this in my own