Here is an attached sample of my problem.
You can create a User, u, and a Folder, f. Assign ownership via a
simple f.owner = u.
You can do an :
objectstore.save(u)
objectstore.save(f)
You can see relations via
print f.owner
print u.objects
But this can not be saved into the database. An
objectstore.flush() will fail with a :
SQLError: (IntegrityError) bases.id may not be NULL 'INSERT INTO bases
(owner_id, creation_date, modification_date, type, title) VALUES (?, ?,
?, ?, ?)' [1, None, None, 'folder', "Le titre de l'object"]
Everything works fine as soon as you remove the owner relation and the
owner_id in the BASES table declaration.
Michael Bayer a écrit :
> it all looks fine to me, youd have to show me something more specific.
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
# -*- coding: UTF-8 -*-
# ***** BEGIN LICENSE BLOCK *****
# This file is part of NOMDUPRODUIT.
# Copyright (c) 2004 laurent Rahuel and contributors. All rights
# reserved.
#
# NOMDUPRODUIT is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# NOMDUPRODUIT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NOMDUPRODUIT; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
from sqlalchemy import mapper, relation, polymorphic_union, create_session
from sqlalchemy import BoundMetaData, Table, Column, Integer, DateTime, Date, Time, String, Boolean, Float, ForeignKey
from datetime import datetime
metadata = BoundMetaData("sqlite:///:memory:")
objectstore = create_session()
#
# Tables definition
#
USERS = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(255), nullable=False),
)
BASES = Table('bases', metadata,
Column('id', Integer, primary_key=True),
Column('owner_id', Integer, ForeignKey('users.id'), primary_key=True),
Column('creation_date', DateTime),
Column('modification_date', DateTime),
Column('type', String(255), nullable=False),
Column('title', String(255), nullable=False),
)
FOLDERS = Table('folders', metadata,
Column('id', Integer, ForeignKey('bases.id'), primary_key=True),
Column('description', String()),
)
#
# Class definition
#
class User(object):
pass
class Base(object):
pass
class Folder(Base):
pass
mapper(User, USERS)
base_join = polymorphic_union(
{
'folder':BASES.join(FOLDERS),
'base':BASES.select(BASES.c.type=='base'),
}, None, 'pjoin')
base_mapper = mapper(Base, BASES, select_table=base_join, polymorphic_on=base_join.c.type, polymorphic_identity='base',properties={'owner': relation(User, primaryjoin=BASES.c.owner_id==USERS.c.id, backref='objects')})
mapper(Folder, FOLDERS, inherits=base_mapper, polymorphic_identity='folder',)
metadata.drop_all()
metadata.create_all()
u = User()
u.name = "Laurent"
f = Folder()
f.title = "Le titre de l'object"
f.owner = u