hi all,
I'm working on a project with an existing SQLite database whose design
I can't change (F-Spot's photo db). The foreign key relationships are
not labeled as such in the tables themselves, so I have to manually
specify them in my mappers. I'm not able to get the many-to-many
relationship between the photo and tag tables working: I keep getting
the following error:
sqlalchemy.exceptions.ArgumentError: No syncrules generated for join
criterion photos.id = photo_tags.photo_id
I've messed around with various settings of cascade and foreignkey,
tried removing the backref, and tried viewonly=True. No dice.
Many thanks in advance for any help with this!
Carl
The schema dump of the three tables is pasted below. Here's the Python
code:
----------------------------------------------------------------
md = BoundMetaData("sqlite://./photos.db")
photo_t = Table('photos', md, autoload=True)
tag_t = Table('tags', md, autoload=True)
photo_tags_t = Table('photo_tags', md, autoload=True)
mapper(Photo, photo_t,
properties={'tags':
relation(Tag, lazy=False, backref="photos",
secondary=photo_tags_t,
foreignkey=[photo_tags_t.c.tag_id,
photo_tags_t.c.photo_id],
primaryjoin=photo_t.c.id==photo_tags_t.c.photo_id,
secondaryjoin=photo_tags_t.c.tag_id==tag_t.c.id)})
mapper(Tag, tag_t)
session = create_session()
sqlite> .schema photos
CREATE TABLE photos (id INTEGER PRIMARY KEY NOT NULL,
time INTEGER NOT NULL,
directory_path STRING NOT NULL,
name STRING NOT NULL,
description TEXT NOT NULL,
default_version_id INTEGER NOT NULL
);
----------------------------------------------------------------
Both mapped objects (Photo, Tag) are defined like:
class Photo(object):
pass
And here are the table schema:
sqlite> .schema tags
CREATE TABLE tags (id INTEGER PRIMARY KEY NOT NULL,
name TEXT UNIQUE,
category_id INTEGER,
is_category BOOLEAN,
sort_priority INTEGER,
icon TEXT );
sqlite> .schema photo_tags
CREATE TABLE photo_tags ( photo_id INTEGER, tag_id
INTEGER );
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---