On Mon, Jul 26, 2010 at 10:32, chaouche yacine <[email protected]> wrote:
> I have used elixir on an early web application with no regrets, and I'm using
> it now for a desktop application.
>
> I had one major problem since then with foreign key constraints (see :
> http://groups.google.com/group/sqlelixir/browse_thread/thread/d7bcb1723f85dc13/97cff1dfc2de5f7a?lnk=gst&q=foreign+key+constraints+not+fired#97cff1dfc2de5f7a).
> Defining fk constraints in sqlalchemy is straight and meaningful. In elixir,
> I found it rather hard to understand.
> An ondelete="RESTRICT" should have been enough but it was not the case.
> Additionally,
> the solution to that problem was to use a passive_deletes = All, which was
> none trivial for me to understand.
Sorry, but I do *not* believe you, and I will not until you show me an
example of plain SQLAlchemy code that does not exhibit the same
behavior that you are blaming on Elixir. I highly suspect there must
have been something else in your code (or a different version of
SQLAlchemy, or I don't know what) which hided the problem. In my tests
(see attached scripts) the behavior is exactly the same whether using
Elixir or SQLAlchemy. Besides, it was also expected that they behave
the same, since Elixir only generates the mapper & table and past that
point it doesn't interfere in *any* way, so it is SQLAlchemy which
provided you with that strange behavior...
> Anyway, I think elixir is a nice piece of code, and provides you with
> additional useful introspection tools that are embedded in your entities
> (like entity._mapper and entity._mapper.get_property).
Note that these are also available when using straight SQLAlchemy (via
class_mapper(entity).xxx). Elixir just stores the mapper in an
attribute, that's all.
--
Gaƫtan de Menten
--
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.
from elixir import *
class Country(Entity):
using_options(tablename="countries")
name = Field(Unicode)
cities = OneToMany('City', passive_deletes='all')
class City(Entity):
using_options(tablename="cities")
name = Field(Unicode)
country = ManyToOne('Country', ondelete='RESTRICT')
metadata.bind = "postgres://@/test"
#metadata.bind = "sqlite://"
metadata.bind.echo = True
drop_all()
setup_all(True)
algeria = Country(name=u"Algeria")
algiers = City(name=u"Algiers", country=algeria)
session.commit()
# THIS DOSEN'T BREAK which is NOT what we want
session.delete(algeria)
session.flush()
session.commit()
from sqlalchemy import *
from sqlalchemy.orm import *
session = sessionmaker()()
metadata = MetaData()
class Base(object):
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
class Country(Base):
pass
class City(Base):
pass
country_table = Table("countries", metadata,
Column('id', Integer, primary_key=True),
Column('name', Unicode)
)
city_table = Table("cities", metadata,
Column('id', Integer, primary_key=True),
Column('name', Unicode),
Column('country_id', Integer, ForeignKey('countries.id',
ondelete='RESTRICT'))
)
mapper(Country, country_table)
# it also fails unless, you pass passive_deletes='all' on the backref!
mapper(City, city_table, properties={
'country': relation(Country, backref=backref('cities'))
# passive_deletes='all'))
})
metadata.bind = "postgres://@/test"
#metadata.bind = "sqlite://"
metadata.bind.echo = True
metadata.drop_all()
metadata.create_all()
algeria = Country(name=u"Algeria")
algiers = City(name=u"Algiers", country=algeria)
session.add_all([algeria, algiers])
session.commit()
# THIS DOSEN'T BREAK which is NOT what we want
session.delete(algeria)
session.flush()
session.commit()