Seach user's id under 2 different columns

Good evening,

I currently have a messaging table which has a hasMany association to conversations that stores the messages for the user.

I am currently trying to search the user’s id with the to_id and from_id column so that i can display the messages that are both sent from and to the user.

I think this is known as a compound query.

How can i go about doing this?

Thanks

Hi Craig,

Suppose the user id is “foobar_user”, then you can retrieve the messages with the following query:

to_id = “foobar_user” OR from_id = “foobar_user”

Do you use the REST API or an SDK?

Regards,
Mark

Hi Mark,

Thanks for the reply :smiley:

I have tried that this morning and it still only presents one row back when it should return 2 rows.

Here is my table:


{
    "nextPage": null,
    "data": [
        {
            "message": null,
            "user_name": "User Two",
            "to_id": "C35E7E97-8330-D63F-FF7E-9DF0D464B400",
            "updated": null,
            "created": "03/06/2014 21:52:58 GMT+0000",
            "from_id": "6A52B80A-0B29-73C2-FF9C-145AEE8DD200",
            "ownerId": null,
            "objectId": "CBC74D11-5815-380F-FF4D-900D7FC1C200"
        },
        {
            "message": null,
            "user_name": "User One",
            "to_id": "6A52B80A-0B29-73C2-FF9C-145AEE8DD200",
            "updated": "03/06/2014 23:41:03 GMT+0000",
            "created": "03/04/2014 23:01:10 GMT+0000",
            "from_id": "C35E7E97-8330-D63F-FF7E-9DF0D464B400",
            "ownerId": null,
            "objectId": "53B4A5BA-1EBD-D756-FF2F-BB6F364F8F00"
        }
    ],
    "offset": 0,
    "totalObjects": 2
}

From the above, my user id of 6A52B80A-0B29-73C2-FF9C-145AEE8DD200 is in both the to_id on one row and the from_id in another so that would need to pull both results under one search.

I use the REST API.

Thanks

Hi Craig,

I created a table called Messages with 2 columns “to” and “from”. I added a few rows into the table (see attached screenshot).

Then I ran the following CURL command:

curl -H application-id:MY-APP-ID -H secret-key:MY-SECRET-KEY -H application-type:REST  -X GET -v "http://api.backendless.com/v1/data/Messages?where=to%20%3D%20%27AAA%27%20or%20from%20%3D%20%27AAA%27"

where the “where” clause is:

to = 'AAA' or from = 'AAA'

Here’s the response I get from Backendless:

{
  "nextPage": null,
  "data": [
    {
      "to": "BBB",
      "updated": "03\/07\/2014 14:42:42 GMT+0000",
      "created": "03\/07\/2014 14:42:40 GMT+0000",
      "objectId": "7F9971D5-D4F0-090C-FF19-4E8E314E8600",
      "ownerId": null,
      "from": "AAA"
    },
    {
      "to": "AAA",
      "updated": "03\/07\/2014 14:42:35 GMT+0000",
      "created": "03\/07\/2014 14:42:31 GMT+0000",
      "objectId": "7A4BDD64-697E-EBD9-FF08-DCC02248CE00",
      "ownerId": null,
      "from": "BBB"
    }
  ],
  "offset": 0,
  "totalObjects": 2
}

Do you see any obvious differences between your and my use-cases?

Regards,
Mark

Hi Mark,

that’s gone and sorted it!

Much appreciated, Backendless rocks!

Craig