I am having an issue with sequelise.js's max query functionality where the "success" object being returned is null despite the logged query being as expected (and working against the database being targeted).
Without further ado here is the codez;
LunaEventDomain
.max("date", {where : { "luna_event_location_id": lunaLocationId }})
.success(function(max) {
console.log("Max object, %s", max);
console.log("Max object is date? [%s]", typeof max == Date);
var result;
if (max == null) {
result = false;
} else {
result = checkHasRecordsAfter(daysInAdvance, max);
}
return result;
})
.error(function(error) {
console.log("Encountered an error from max query, [%s]", error);
});
Snippet 1: The max query code.
The log notes;
Executing (default): SELECT max(`date`) as `max` FROM `luna_event` WHERE `luna_event`.`luna_event_location_id`='1';
Max object, null
Max object is date? [false]
Snippet 2: The resulting log.
The LunaEventDomain table has (MySQL) schema;
id int(11)
event_type enum('LOW_WATER', 'HIGH_WATER', 'MOONRISE', 'MOONSET')
date datetime
height decimal(10,3)
luna_event_location_id int(11)
When I execute the logged query against the target database I retrieve an appropriate response. What am I doing wrong? I would like the max result to be delivered as part of the success(function(max) { ... }) callback.
Looks like this is me not understanding sequelisejs#sync which clears down the db between server restarts. The max query returns as expected after the 2nd request!