Re: Forcing second join

Nikita Timofeev <[email protected]> Thu, 2 Oct 2025 17:50:35 +0400
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CAMi+qzBzps3PGUAqUAx=kgLTkpQ9Y5NTyTXuOG=HWLmqdjqxig@mail.gmail.com>
--000000000000910fd306402d46b9
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello Ricardo,

Yes, Cayenne supports that, the easiest option is an `alias()` function in
the Property API:

ObjectSelect.query(Artist.class)

.where(Artist.PAINTING_ARRAY.alias("p1").dot(Painting.PAINTING_TITLE).start=
sWith("A"))

.and(Artist.PAINTING_ARRAY.alias("p2").dot(Painting.PAINTING_TITLE).startsW=
ith("G"))
    .select(context);

On Thu, Oct 2, 2025 at 4:37=E2=80=AFAM Ricardo Parada <[email protected]=
lid>
wrote:

>
> Hello,
>
> I=E2=80=99m wondering if it=E2=80=99s possible to force a second join to =
a table. For
> example:
>
> paintings.name like A% AND paintings.name like G%
>
> In a SQL query, this will always return 0 records because a given paintin=
g
> cannot start with the letter A and G at the same time.  It either starts
> with one or the other.
>
> So if I=E2=80=99m looking for artists that have a painting with its name =
starting
> with the letter A and another one with the letter G then the SQL would ha=
ve
> to do a second join.
>
> For example,
>
> SELECT * FROM ARTIST t0
> JOIN PAINTING t1 ON t1.ARTIST_ID =3D t0.ID
> JOIN PAINTING t2 ON t2.ARTIST_ID =3D t0.ID
> WHERE t1.NAME LIKE =E2=80=98A%=E2=80=99
> AND  t2.NAME LIKE =E2=80=98G%=E2=80=99
>
> Thanks in advance,
> Ricardo Parada
>
>
>
>

--=20
Best regards,
Nikita Timofeev

--000000000000910fd306402d46b9--