On Thu, 2010-07-08 at 08:28 -0700, chaouche yacine wrote:
> Put another way : how can I access the class that the country_id attribute
> referes to ?
> ...
> 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.
Hope it helps,
Gaëtan
--
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.