# How to create a join using a reference field

**URL:** https://discuss.tryton.org/t/how-to-create-a-join-using-a-reference-field/6568
**Category:** Developer
**Created:** [October 5, 2023, 1:16am UTC](https://discuss.tryton.org/t/how-to-create-a-join-using-a-reference-field/6568 "2023-10-05T01:16:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [October 5, 2023, 1:16am UTC](https://discuss.tryton.org/t/how-to-create-a-join-using-a-reference-field/6568/1 "2023-10-05T01:16:13Z")

</div>

**I want to join move.shipment and shipment.id**

```
    if 'move.shipment' not in tables:
        shipment = Shipment. __table__ ()
        tables['move.shipment'] = shipment
        from_item = (from_item
            .join(shipment, condition=move.shipment == shipment.id))

```

**I receive this error.**

psycopg2errorsUndefinedFunction: operator does not exist: character varying = integer  
LINE 1: IN “stock\_shipment\_out” AS “k” ON (“b”“shipment” = “k”“id”  
^  
HINT: No operator matches the given name and argument types You might need to add explicit type casts

Also is related with this

```
@classmethod
def _where(cls, tables, withs):
    Shipment = Pool().get('stock.shipment.out')
    
    context = Transaction().context
    shipment = Shipment. __table__ ()
    move = tables['move']
    where = super()._where(tables, withs)
    customer = context.get('customer')
    
    if customer:
        where &= shipment.customer == customer
    return where

```

I receive this error

psycopg2errorsUndefinedTable: missing FROM-clause entry for table “k”  
LINE 1: “b”“effective\_date” \<= ‘2023-10-04’::date)) AND (“k”"custo

---

<div class="post-metadata">

### Author: ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)
#### Post date: [October 5, 2023, 7:44am UTC](https://discuss.tryton.org/t/how-to-create-a-join-using-a-reference-field/6568/2 "2023-10-05T07:44:50Z")

</div>

move.shipment is a tuple with: shipment\_model, id

Try something like this:

```auto
from_item = (from_item
        .join(shipment, (Concat(Shipment. __name__ + ',', shipment.id)) == move.shipment))

```

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [October 5, 2023, 4:08pm UTC](https://discuss.tryton.org/t/how-to-create-a-join-using-a-reference-field/6568/3 "2023-10-05T16:08:51Z")

</div>

It works like a charm! Thanks

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [October 5, 2023, 7:45pm UTC](https://discuss.tryton.org/t/how-to-create-a-join-using-a-reference-field/6568/4 "2023-10-05T19:45:36Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
