--- On Thu, 7/8/10, Gaëtan de Menten <[email protected]> wrote:

> >     def
> get_class_of(relation_name):
> >         """
> >     
>    self.get_class_of("country_id") ==
> Country
> >         """
> >         # How do I write
> this ? can self.mapper.get_property(relation_name) lead to
> the relation's class ?
> 
> Yes. mapper.get_property(relation_name).mapper.class_
> 
> > algeria = Country("Algeria")
> > session.flush()
> > algiers = City("Algiers",country_id=algeria.id)
> > 
> > # The purpose of all this is to have algiers.country
> == algeria, merely by passing country_id to City.
> > print algiers.country
> 
> But you have another option here: you could simply flush
> once more
> (after instanciating "algiers" normally and only setting
> its country_id
> attribute) and let the ORM do its job.

Thank you Gaëtan, indeed after the second flush the instances are related 
correctly and transparently. I wonder why it doesn't work like this in a real 
life example (our current application) though instances are loaded via 
ModelClass.query.all(). I'll have to look deeper into that nasty code.

Thanks again. 



      

-- 
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en.

Reply via email to