Hi, I'm new in TG2 and new in SQLAlchemy. I've some experience
developing in TG1 and SQLObject. I'm using SQLite.

The problem is that I could create an instance without given data to
an attribute that is a foreign key to another instance.

My model.py is:
class Document(DeclarativeBase):
    __tablename__ = 'documents'

    document_id = Column(Integer, autoincrement=True,
primary_key=True) # id Documento
    path = Column(Unicode(255))

    revisions = relation('Revision', backref='documents')

class Revision(DeclarativeBase):
    __tablename__='revisions'

    revision_id = Column(Integer, autoincrement=True,
primary_key=True) # id Revision
    description = Column(Unicode(255))
    document_id = Column(Integer, ForeignKey('documents.document_id'))

Then, I've started a shell and did this:
>>> rev1 = model.Revision(description = u"Revision Nro 1")
>>> model.DBSession.add(rev1)
>>> model.DBSession.flush()
17:05:17,250 INFO  [sqlalchemy.engine.base.Engine.0x...2570]
[u'Revision Nro 1', None]
>>> for i in model.DBSession.query(model.Revision).all():
...     print i.revision_id, i.description, i.document_id
...
1 Revision Nro 1 None

Why document_id is None? In SQLObject I could have an Exception
telling that document_id is needed. An another one if I wanted to
relate to a document that doesn't exists. Here I din't have this
error.
>>> rev2 = model.Revision(description = u"Revision Nro 2", document_id = 10)
>>> model.DBSession.add(rev2)
>>> model.DBSession.flush()
>>> for i in model.DBSession.query(model.Revision).all():
...     print i.revision_id, i.description, i.document_id
...
1 Revision Nro 1 None
2 Revision Nro 2 10
>>>

I couldn't find my error, I was trying to do same as in Movie tutorial
in TG2 documentation.
Thanks, Matías
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to