You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Andres L." <an...@gmail.com> on 2013/11/10 20:38:50 UTC

Help with FK

I have some tables. One of them called COTIZACION with fields
"idProveedor", "idOrdenCompra", and "fecha" (date), where "idProveedor" and
"idOrdenCompra" are FK to tables PROVEEDOR and ORDENCOMPRA. When I make a
query by id  from ORDENCOMPRA (which is ORDENCOMPRA PK) and I get the
value, I need to get the COTIZACION value that has a relationship with
ORDENCOMPRA. How can I make it?

Thank you in advance.

Re: Help with FK

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Andres,

First you will need to map a relationship based on your FK/PK pair (both DbRelationship and ObjRelationship) [1]. Once you have that in the model and regenerate your java classes, your Ordencompra object will have a method like ‘getCotizacions’, returning a collection of related objects. So you can use that. Or you can build a query based on a know Ordencompra as a criteria:

Ordencompra o = ..
SelectQuery q = new SelectQuery(Cotizacion.class);
q.andQualifier(ExpressionFactory.matchExp(Cotizacion.ORDENCOMPRA_PROPERTY, o);

Hope this helps,
Andrus

[1] http://cayenne.apache.org/docs/3.1/tutorial/ch03.html#mapping-db-relationships

On Nov 10, 2013, at 10:38 PM, Andres L. <an...@gmail.com> wrote:

> I have some tables. One of them called COTIZACION with fields
> "idProveedor", "idOrdenCompra", and "fecha" (date), where "idProveedor" and
> "idOrdenCompra" are FK to tables PROVEEDOR and ORDENCOMPRA. When I make a
> query by id  from ORDENCOMPRA (which is ORDENCOMPRA PK) and I get the
> value, I need to get the COTIZACION value that has a relationship with
> ORDENCOMPRA. How can I make it?
> 
> Thank you in advance.