I think I misunderstood the use of the association proxy -- I don't
think I want to use it in this case anymore...
thx
m
On Oct 31, 6:33 pm, Matt <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have a table (Content) which relates to itself via a many-to-many
> relationship through a link table (ContentCollection). I'm trying to
> setup parent/child relationships for the Content table using the
> association_proxy since there are some fields I'll need to modify in
> ContentCollection:
>
> class Content(object):
> children = association_proxy('collection_children', 'child')
> parents = association_proxy('parent_collections', 'parent')
>
> class ContentCollection(object):
> pass
>
> Session.mapper(Content, content,properties={
> 'collection_children' : relation(ContentCollection,
> primaryjoin=content.c.id==content_collection.c.collection_id,
> cascade="all, delete, delete-orphan"),
> 'parent_collections' : relation(ContentCollection,
> primaryjoin=content.c.id==content_collection.c.content_id,
> cascade="all, delete, delete-orphan")
>
> })
>
> Session.mapper(ContentCollection, content_collection, properties={
> 'child' : relation(Content,
> primaryjoin=content.c.id==content_collection.c.content_id),
> 'parent' : relation(Content,
> primaryjoin=content.c.id==content_collection.c.collection_id),
>
> })
>
> Read access seems to work as I'd expect, but when I add an item using
> Content.children.append(item), I get something like:
>
> sqlalchemy.exceptions.OperationalError: (OperationalError) (1048,
> "Column 'content_id' cannot be null") u'INSERT INTO content_collection
> (priority, home, version, creation_time, modification_time,
> collection_id, content_id, is_primary) VALUES (%s, %s, %s,
> UTC_TIMESTAMP(), UTC_TIMESTAMP(), %s, %s, %s)' [0, None, None, 79940L,
> None, None]
>
> Seems to only be supplying the id for the child and not the parent
> when it's creating the intermediate table record... Any ideas what
> I'm doing wrong here?
>
> thx
>
> Matt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---