Find all users that has an attached property of a specific id


#1

Hi!

I want to find all the users that has an attached property of a specific ID.
How should I write the code for that?


#2

Realised that it was a bit described complicated:

I’ll try to explain better:

One user can create a tag, and a user can have multiple tags. A tag can have multiple users - Its a many to many relation.

So if I want to find all users that has tag_id = 1, for example.


#3

Have you setup the relationship in Lucid models yet?


#4

Yes, I have the relationship setup. So I can attach and detach the tags from a user

EDIT: A moment after responding, I realised how I can do it. To retrieve all tags from a user, I use User.find(user_id).tags().fetch(). I should be able to use Tags.find(tag_id).users().fetch().
Which works, so it’s solved.