Hi list,
I tried to follow this advice from gaƫtan
http://groups.google.com/group/sqlelixir/browse_thread/thread/43c76ab74be218e8/fb7fe0070edd56fa?#fb7fe0070edd56fa
to try to update a relation simply by passing the associated id to it. (a.b_id
= b.id and then assert a.b == b)
But the following code shows that something is going wrong when I print a.b
before setting a.b_id and flushing.
Versions :
(my-coriolis)chaou...@jogger:/usr/share/pyshared/elixir$ python -c "import
elixir; print elixir.__version__"
0.7.1
(my-coriolis)chaou...@jogger:/usr/share/pyshared/elixir$ python -c "import
sqlalchemy; print sqlalchemy.__version__"
0.5.8
(my-coriolis)chaou...@jogger:/usr/share/pyshared/elixir$ python --version
Python 2.6.5
(my-coriolis)chaou...@jogger:/usr/share/pyshared/elixir$
--------
from elixir import *
class BaseModel(Entity):
using_options(abstract=True)
def __repr__(self):
return "<%s '%s'>" % (self.__class__.__name__,self.name)
class Person(BaseModel):
using_options(tablename = "persons")
name = Field(String)
city = ManyToOne("City")
class Country(BaseModel):
"""
"""
using_options(tablename = "countries")
name = Field(String)
cities = OneToMany("City")
class City(BaseModel):
"""
"""
using_options(tablename = "cities")
name = Field(String)
country = ManyToOne("Country")
persons = OneToMany("Person")
algeria = None
algiers = None
blida = None
def create():
global algeria,blida,algiers
algeria = Country(name="Algeria")
algiers = City(name="Algiers")
blida = City(name="Blida")
session.commit()
def load():
global algeria,blida,algiers
algeria = Country.get(1)
algiers = City.get(1)
blida = City.get(2)
metadata.bind = "postgres://some_db"
session.bind = metadata.bind
setup_all()
drop_all()
create_all()
create()
load()
# Uncomment this line and you'll get None the second time you print
algiers.country (after the flush)
print "before",algiers.country
algiers.country_id = algeria.id
session.flush()
print "after",algiers.country
print algeria.cities
Any help appreciated.
--
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.