Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findBySmth has doubles #846

Open
naturalcod opened this issue Oct 13, 2019 · 0 comments
Open

findBySmth has doubles #846

naturalcod opened this issue Oct 13, 2019 · 0 comments

Comments

@naturalcod
Copy link

naturalcod commented Oct 13, 2019

Hi. i broke my head.

I have this:
this.req.models.Tour.findByInfo({ Charter: this.req.query.Charter, }, { autoFetch: false }).where("Active = 1",(err, tours) => { this.res.end(JSON.stringify(tours)) })

This is what I get. At the output, I get:

[ { "Title": "Тур в горы", "Rating": 9, "Description": "Ахуенный тур", "Active": true, "MinDate": null, "MaxDate": null, "id": 1, "owner_id": 1, "town_id": 1 }, { "Title": "Тур в горы", "Rating": 9, "Description": "Ахуенный тур", "Active": true, "MinDate": null, "MaxDate": null, "id": 1, "owner_id": 1, "town_id": 1 }, { "Title": "Тур в горы", "Rating": 9, "Description": "Ахуенный тур", "Active": true, "MinDate": null, "MaxDate": null, "id": 1, "owner_id": 1, "town_id": 1 }, { "Title": "Тур в горы", "Rating": 9, "Description": "Ахуенный тур", "Active": true, "MinDate": null, "MaxDate": null, "id": 1, "owner_id": 1, "town_id": 1 } ]

I understand what the problem is, so JOIN works. SQL:

SELECT t1.Title, t1.Rating, t1.Description, t1.Active, t1.MinDate, t1.MaxDate, t1.id, t1.owner_id, t1.town_id FROM Tour t1 JOIN TourInfo t2 ON t2.tour_id = t1.id WHERE (t2.Charter = '1' AND t2.Price BETWEEN 0 AND 999999999) AND (Active = 1)

BUT i NEED so SQL:

SELECT DISTINCT(t1.id), t1.Title, t1.Rating, t1.Description, t1.Active, t1.MinDate, t1.MaxDate, t1.owner_id, t1.town_id FROM Tour t1 JOIN TourInfo t2 ON t2.tour_id = t1.id WHERE (t2.Charter = '1' AND t2.Price BETWEEN 0 AND 999999999) AND (Active = 1)

OR

SELECT t1.id, t1.Title, t1.Rating, t1.Description, t1.Active, t1.MinDate, t1.MaxDate, t1.owner_id, t1.town_id FROM Tour t1 JOIN TourInfo t2 ON t2.tour_id = t1.id WHERE (t2.Charter = '1' AND t2.Price BETWEEN 0 AND 999999999) AND (Active = 1) GROUP BY t1.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant