1

I'm trying to use the pet-owner example to create some sort of playlist app where a playlist can be shared among different users.

I have read both links to understand how many-to-many relationship is created in Backand:

Link 1 - Link 2

According to pet's example, to get all owners from one pet I should get the pet object (using its id field) and then filter its user_pets list matching the user id. That may work for small amount of users/pets but I'd rather prefer to query user_pets table directly by filtering by user_id and pet_id.

My approach has been this code without success:

$http({
  method: 'GET',
  url: getUrl(),  // this maps to pets_owner "table"
  params: {
    deep: true,
    exclude: 'metadata',
    filter: [
      { fieldName: 'pet', operator: 'equals', value: pet_id },
      { fieldName: 'owner', operator: 'equals', value: user_id }
    ]
  }
})

Any idea how to query/filter to get only related results?

Thanks in advance

neer
  • 4,031
  • 6
  • 20
  • 34
  • Note that my code is intented to resolve one main situation: get the relationship id and then send a DELETE to REST API to delete it. If this can be done in another way it will be fine. – user3401368 Jun 08 '16 at 14:44

1 Answers1

1

Because user_id and pet_d are both object fields the operator should be "in"

From Backand docs :

following are the possible operators depending on the field type:

numeric or date fields:

-- equals

....

object fields:

-- in

Community
  • 1
  • 1
user3375230
  • 421
  • 2
  • 5