Am 11.06.2013, 23:47 Uhr, schrieb Andy <[email protected]>:

I could do that, but I'd change the foreign key in favorites to point at
group_things, since your favorite group must be a group that you're in.
Then I'd drop the other foreign key constraint as unnecessary, since it's
implied by the new one, and then I'd be back at square one (needing to
convince the ORM to understand a relation with no real foreign key).

Ah, okay. I think I understand what I was missing initially. I've had another go at this and it seems to work as required, even on MySQL. Not sure how this all works with SQLAlchemy but I would expect it to be fine with it.

insert into favourites (thing_id, group_id) values (2, 2)
Error Code: 1062. Duplicate entry '2' for key 'PRIMARY' 0.012 sec

insert into favourites (thing_id, group_id) values (1, 3)
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails ("favourites"."favourites", CONSTRAINT "checker" FOREIGN KEY ("thing_id", "group_id") REFERENCES "groups_things" ("thing_id", "group_id")) 0.007 sec

Also, SERIAL?  You must be using a real database engine.

Well, er, yes. When it comes to modelling that's where you should start. And Oracle is making progress with MySQL now that InnoDB with separate files pro table and 5.6 even seems to have some kind of vacuuming built-in.

Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226

--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Attachment: favourites.sql
Description: Binary data

Reply via email to