Am Montag 25 August 2008 22:37:47 schrieb Michael Bayer: > On Aug 25, 2008, at 12:22 PM, Hermann Himmelbauer wrote: > > Hi, > > I'm wondering if the following is possible with mappers: > > > > I have two tables A and B, whereas B is referenced by A. What I need > > is a > > special mapper for A that returns all referenced rows in B except > > those, that > > have a specific value in one column of the row, e.g.: > > > > Table A: > > id, sometext, reftoB > > 1, xyz, 1 > > 2, abc, 2 > > > > Table B: > > id, sometext > > 1, foo > > 2, NOTTHISONE <- Should not be returned by the mapper > > > > Is there a simple way to achieve this? > > I'm not 100% clear on what you're asking since it seems like you are > looking for a list of "A" based on something in B, but you said > "returns all referenced rows in B". If you just wanted all Bs > without "sometext=NOTTHISONE" thats just query(B).filter(B.sometext! > ='NOTTHISONE').
Yes, that's exactly what I need, yes. The only thing is, that I'd like to have this as a mapper property. The background for all this is the following: - In my existing database, I have relations to other tables, which don't necessarily need to exist, so it's simply a ForeignKey without "not null". - Unfortunately, the design is based on an old, existing database, which did not support NULL / referential integrity, therefore we inserted "0" for NULL (= no reference). This logic is implemented in a very old C-Client code, which I don't want to overwork, but to which we need to maintain compatibility. - With SQLAlchemy, ForeignKey() creates referential integrity, which is basically a good thing, however, these "0" references, which have no counterpart in another table, violate the integrity constraints. So there are basically two options: - Somehow tell the database, that "0" is a NULL value, too. (That does not seem to be possible). - Somehow disable referential integrity (but I don't really know how, moreover, I'd probably have to rewrite the mappers, whereas I also don't really know how). - Insert a dummy row, which id "0" into all referenced tables. The old C-Code would never get these, as it does not try to reference "0"-references. The only thing to do here would be to rewrite my mappers, so that they don't get these 0-references back. Thanks for help! Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---