[Vuejs]-Filtering the value in Array with the value in another array

0👍

You should select in such a way So that for every scenario you should have every user’s permissions for the given scenario.

You should be able to do this by taking a join of these tables. so that you get the users with permissions for a given scenario something like this:

SELECT s.user_id, u.user_active, s.scenario_id FROM Scenario_Users s INNER JOIN Users u on u.user_id = s.user_id

this will give you something like this :

[
    {
        "user_id":1,
        "user_active": 1,
        "scenario_id":3 
    },
    {
        "user_id":1,
        "user_active": 0,
        "scenario_id":1 
    }
]

if you want the users having access to a particular scenario you can query like this:

Select user_id, user_active from Scenario_Users WHERE scenario_id = 1

this will give you the list like this:

[
  {
   user_id: 1,
   user_active: 1
  },
  {
   user_id: 16,
   user_active: 1
  }
]

You should have a user_active column in the Scenario_Users table So that you can specify the access to a scenario for a particular user. But you are defining the user_active column in the Users table but it does not specify the scenario for which the user is active [when user_active = 1].

But According to your Users table and Scenario_Users Table, it is not clear that how you are defining the relation between user’s Access to a particular scenario.

In your case, it seems like you are storing only the users in the Scenario_Users table of a user who has permission to a particular scenario, and your User table shows if a user is active or not.

So there seems no relation in tables for the scenario.

the JSON you want can be obtained by simply selecting data from your Users table

Select user_id, user_active from Users

Leave a comment