# Order of variables matters when attributes are passed as arguments

**URL:** https://forum.datomic.com/t/order-of-variables-matters-when-attributes-are-passed-as-arguments/1345
**Category:** Datomic Pro
**Created:** [February 4, 2020, 12:55pm UTC](https://forum.datomic.com/t/order-of-variables-matters-when-attributes-are-passed-as-arguments/1345 "2020-02-04T12:55:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![apopelo](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/apopelo/32/313_2.png) [@apopelo](https://forum.datomic.com/u/apopelo)
#### Post date: [February 4, 2020, 12:55pm UTC](https://forum.datomic.com/t/order-of-variables-matters-when-attributes-are-passed-as-arguments/1345/1 "2020-02-04T12:55:20Z")

</div>

Lets consider the next schema and example data:

```
(def user-schema [
                    {
                      :db/ident :user/kind
                      :db/valueType :db.type/string
                      :db/cardinality :db.cardinality/one
                   }
                   {
                       :db/ident :user/name.EN
                       :db/valueType :db.type/string
                       :db/cardinality :db.cardinality/one
                   }
                   {
                       :db/ident :user/name.ES
                       :db/valueType :db.type/string
                       :db/cardinality :db.cardinality/one
                   }

                   ])
(d/transact conn user-schema)

(def user-data [
  {
    :user/kind "owner"
    :user/name.EN "Boby"
    :user/name.ES "Doby"
  }
  {
    :user/kind "owner"
    :user/name.EN "Doby"
    :user/name.ES "Boby"
  }
  {
    :user/kind "owner"
    :user/name.EN "Mobi"
    :user/name.ES "Tobi"
  }
])
(d/transact conn user-data)

```

I want to search for any entity which has either **name.EN** or **name.ES** equal to **Doby**.

```
(d/q "[
:find ?user 
:in $ ?userKind [?userNameValues ...] [?userNameAttrs ...] 
:where 
  [?user :user/kind ?userKind]
  [?user ?userNameAttrs ?userNameValues]
]"
(d/db conn), "owner" ["Doby"] [:user/name.EN :user/name.ES] )

```

The result of query is empty

But if to swap **?userNameValues** and **?userNameAttrs** then all works:

```
(d/q "[
:find ?user 
:in $ ?userKind [?userNameAttrs ...] [?userNameValues ...]
:where 
[?user :user/kind ?userKind]
[?user ?userNameAttrs ?userNameValues]
]"
(d/db conn), "owner" [:user/name.EN :user/name.ES] ["Doby"] )

#{[17592186045629] [17592186045630]}

```

As you see two elements were returned. What is more interesting, the first query works when to remove the first condition:

```
(d/q "[
:find ?user 
:in $ ?userKind [?userNameValues ...] [?userNameAttrs ...] 
:where 
  [?user ?userNameAttrs ?userNameValues]
]"
(d/db conn), "owner" ["Doby"] [:user/name.EN :user/name.ES] )

#{[17592186045629] [17592186045630]}
```

---

<div class="post-metadata">

### Author: ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)
#### Post date: [February 4, 2020, 3:58pm UTC](https://forum.datomic.com/t/order-of-variables-matters-when-attributes-are-passed-as-arguments/1345/2 "2020-02-04T15:58:20Z")

</div>

What version of Datomic are you using?  
Are you using the client of the peer api?

I was able to make a simple reproduction of this approach and did not see the same problem.

---

<div class="post-metadata">

### Author: ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)
#### Post date: [February 4, 2020, 4:06pm UTC](https://forum.datomic.com/t/order-of-variables-matters-when-attributes-are-passed-as-arguments/1345/3 "2020-02-04T16:06:48Z")

</div>

I made an adjustment and was able to reproduce the behavior you’re seeing.  
We will investigate.
