use sequelize include option when querying real estates from matches
This commit is contained in:
@@ -6,9 +6,19 @@ const findRealEstatesForSearchRequest = async searchRequestId => {
|
|||||||
searchRequestId
|
searchRequestId
|
||||||
};
|
};
|
||||||
|
|
||||||
const include = [{ model: db.RealEstate }];
|
const include = [{ model: db.RealEstate, as: "realEstates" }];
|
||||||
|
|
||||||
return await db.SearchRequestMatch.findAll({ where: query, include });
|
const matches = await db.SearchRequestMatch.findAll({
|
||||||
|
where: query,
|
||||||
|
include
|
||||||
|
});
|
||||||
|
|
||||||
|
const matchingRealEstates = [];
|
||||||
|
for (const match of matches) {
|
||||||
|
matchingRealEstates.push(...match.realEstates);
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchingRealEstates;
|
||||||
};
|
};
|
||||||
|
|
||||||
const addMatches = async matchingRecords => {
|
const addMatches = async matchingRecords => {
|
||||||
|
|||||||
Reference in New Issue
Block a user