On Feb 24, 2010, at 7:59 PM, f3d wrote:

> Hello,
> 
> Guess I haven't understood all the magic behind object mapping...
> 
> I have a class like this :
> 
> class MyClass(object):
> 
>    __init__(self, name):
> 
>        self = session.query(MyClass).filter(MyClass.name==name).one()
>        print self.name # Outputs 'joe'
> 
> And I'm expecting that my instance of MyClass has its attributes filled
> with the correct values, they are instead empty, while issuing for
> example print self.name inside the __init__ method reports the expected
> values :

you can't change the value of "self" inside the __init__ method of an object.  
That's just Python.  You probably want to use __new__, as in 
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject .




> 
>>>> obj = MyClass('joe')
>>>> obj.name
>>>> 
> 
> I've tried prepending __init__ with the @orm.reconstructor stuff without
> success too.
> 
> Could someone enlighten me, and show me the way to handle this the right
> way ?
> 
> Regards.
> 
> 
> -- 
> f3d
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> 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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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