Re: Querying for objects where the primary key does not equal a supplied value

From: Bryan Lewis (brya..aine.rr.com)
Date: Thu Mar 31 2005 - 23:53:22 EST


Are you aware that you can refer to database attributes in queries by
prefixing "db:"?

http://objectstyle.org/cayenne/userguide/expressions/common.html

----- Original Message -----
From: "Craig Turner" <crai..ecalldesign.com>
To: <cayenne-use..bjectstyle.org>
Sent: Thursday, March 31, 2005 8:58 PM
Subject: Querying for objects where the primary key does not equal a
supplied value

> Thanks for the help with the issue yesterday guys.
>
> I've found some resoures on getting an object out by its primary key,
> but is there a way to query by items that don't match a given primary key?
>
> Late yesterday I was trying to construct a query that excluded matches
> of the primary key for a table. The situation is that I have a series of
> locations, and their names must be unique. As part of validation I
> wanted to run a query to do this:
>
> select *
> from Location l
> where 1=1
> and lower(l.name) = '{location name to validate}'
> and id <> '{object I'm currently using}'
>
>
> The solution I ended up using to get around this was to get all results
> with a matching name, and then to the item I'm using from the list, and
> then see if there's anything left in the list. There's an alternative
> solution where you find out whether this is a new object or an existing
> object, and treat them differently. This gets complicated because you
> need to buffer the location name of the existing object in case of a
> name change. Both solutions seem less than ideal.
>
> (While trying to get this working, at one point I tried adding the id to
> the entity in the cayenne interface. However when I did this I think the
> object stopped creating the primary key automatically for new objects)
>
> - C



This archive was generated by hypermail 2.0.0 : Thu Mar 31 2005 - 23:53:30 EST