On Tuesday, June 29, 2010 18:54:57 chaouche yacine wrote:
> --- On Tue, 6/29/10, Diez B. Roggisch <[email protected]> wrote:
> > You don't make country a required field. So SQLAlchemy will
> > set it to NULL,
> > which is perfectly fine from the model.
> >
> > Add a "required=True" parameter to the
> > ManyToOne-Country-declaration.
> >
> >
> >
> > Diez
>
> What I want is that the delete operation raises a
> "sqlalchemy.exc.IntegrityError: (IntegrityError)", and I think that
> required=True dosen't help here, I added it with no results (delete still
> passes).
Not for me, but I also added a commit....
from elixir import *
class BaseModel(Entity):
using_options(abstract=True)
repr_attr = "name"
def __repr__(self):
"""
"""
return "<%s '%s' id='%s'>" %
(self.__class__.__name__,getattr(self,self.repr_attr,id(self)),self.id)
class Country(BaseModel):
"""
"""
using_options(tablename = "countries")
name = Field(Unicode)
cities = OneToMany("City")
class City(BaseModel):
"""
"""
using_options(tablename = "cities")
name = Field(Unicode)
country = ManyToOne("Country",ondelete="RESTRICT", required=True)
metadata.bind = "postgres://localhost/test"
metadata.bind.echo = True
# I use this to issue some raw sql (truncate not supported by sqla/elixir ?)
session.bind = metadata.bind
drop_all()
setup_all(True)
# This line will break if uncommented, because of fk constraints
#session.execute("TRUNCATE TABLE cities")
session.execute("TRUNCATE TABLE countries CASCADE")
session.commit()
# just to make them global
algeria = None
algiers = None
def create():
global algeria,algiers
algeria = Country(name=u"Algeria")
algiers = City(name=u"Algiers",country=algeria)
session.commit()
algeria.delete()
def delete():
global algeria,algiers
# THIS DOSEN'T BREAK which is NOT what we want
algeria.delete()
session.flush()
create()
delete()
session.commit()
Diez
--
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.