Hi,

On 01/03/2013 15:59, Werner wrote:
Hi,

Found it in the doc, the "Adjacency List Relationship" is what I wanted.

http://docs.sqlalchemy.org/en/latest/orm/relationships.html#adjacency-list-relationships
I am having a problem when I try to delete an item where I use this, I get this exception:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) (-530, 'isc_dsql_execute: \n violation of FOREIGN KEY constraint "WINERACKU_FK_COMBRACK_ID" on table "WINERACKU"\n Foreign key references are pres ... (truncated)
File "c:\dev\twcbv4\twcbsrc\controllers\dwinerack.py", line 268, in <module>
  dlg.ShowModal()
File "c:\Python27\Lib\site-packages\wx-2.9.5-msw\wx\_windows.py", line 805, in ShowModal
  return _windows_.Dialog_ShowModal(*args, **kwargs)
File "c:\dev\twcbv4\twcbsrc\controllers\fwinerackdesign.py", line 391, in deleteUnit
  self.doListItemDelete(runit)
File "c:\dev\twcbv4\twcbsrc\controllers\base.py", line 1437, in doListItemDelete
  self._controller.ds.commit()
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\session.py", line 719, in commit
  self.transaction.commit()
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\session.py", line 352, in commit
  self._prepare_impl()
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\session.py", line 332, in _prepare_impl
  self.session.flush()
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\session.py", line 1814, in flush
  self._flush(objects)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\session.py", line 1896, in _flush
  flush_context.execute()
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\unitofwork.py", line 372, in execute
  rec.execute(self)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\unitofwork.py", line 553, in execute
  uow
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\persistence.py", line 115, in delete_obj
  cached_connections, mapper, table, delete)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\orm\persistence.py", line 677, in _emit_delete_statements
  connection.execute(statement, del_objects)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\engine\base.py", line 664, in execute
  params)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\engine\base.py", line 764, in _execute_clauseelement
  compiled_sql, distilled_params
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\engine\base.py", line 878, in _execute_context
  context)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\engine\base.py", line 871, in _execute_context
  context)
File "c:\Python27\Lib\site-packages\sqlalchemy-0.8.0-py2.7.egg\sqlalchemy\dialects\firebird\base.py", line 724, in do_execute
  cursor.execute(statement, parameters or [])

Do I have to manually clear out the foreign keys first or can I fix it by correctly setting things in the model?

I currently have:

StandardColumnMixin creates the "id" and date/user creation/update columns.

class Winerack(DeclarativeBase, mix.StandardColumnMixin):
    __tablename__ = u'winerack'

    name = sa.Column(sa.Unicode(length=30))
...

class Wineracku(DeclarativeBase, mix.StandardColumnMixin):
    __tablename__ = u'wineracku'

    description = sa.Column(sa.Unicode(length=30))
...
    fk_winerack_id = sautils.reference_col('winerack')

    fk_combrack_id = sa.Column(cts.KEYS, sa.ForeignKey('wineracku.id'))

Winerack.wineracku = sao.relationship('Wineracku', backref='winerack',
                                      cascade="all, delete, delete-orphan")
Wineracku.winerackb = sao.relationship('Winerackb', backref='wineracku',
cascade="all, delete, delete-orphan") Wineracku.combrack = sao.relationship('Wineracku', remote_side=[Wineracku.id],
                                      cascade="all, delete, delete-orphan",
                                      single_parent=True)

Werner

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to