Hello friends! I had some time without asking around here because it has been easy for me to find a solution to the problems that I have encountered, but right now I am facing a wall.
I have this query:
const themes = await Theme.query() .with('users') .orderBy('created_at', 'DESC') .paginate(params.page, 3)
I am trying to filter the “id” of the user in session by looking in the “users” table so that the “theme” does not return if there is the “id” of our user, there is no way to do it … I tried to replace the previous method for this :
const theme = await Theme.query() .select('users.id AS tenertema', 'theme.id AS id', 'theme.nombretema AS nombretema', 'theme.creador AS creador', 'theme.estilonavbar AS navbar', 'theme.estiloiconos AS iconos', 'theme.estilopagina AS pagina', 'theme.background AS Fondo', 'theme.userbox AS ubox', 'theme.postbox AS pbox', 'theme.colortexto AS texto', 'theme.moneda AS pay', 'theme.precio AS price', 'theme.created_at AS created' ) .from('users') .leftJoin('interthemes as IT', 'IT.user_id', '=', 'users.id') .leftJoin('themes as theme', 'IT.theme_id', '=', 'theme.id') .whereNot('theme_id', null) .whereNot('user_id', null) .where('user_id',user.id) .orderBy('created', 'DESC') .paginate(params.page, 3)
What is the main problem of this? is that being a many-to-many relationship, the object that belongs to my user not return but the same “theme” return when it belongs to other users, that is, the object is multiplied with each user to whom it belongs, it has been a Headache recently i ask after two or three days of searching without finding a solution Thank you very much in advance!