Finding record between startOfDay and endOfDay using Entity.all().filter().and();

79 views
Skip to first unread message

rvkone

unread,
Mar 21, 2014, 10:06:26 AM3/21/14
to persis...@googlegroups.com
First, thanks for this great plugin.
I'm using persistencejs (the latest grabbed by bower) for one of my angularjs service. 
Every thing seems ok until I need to grab some records between the start and end of a given day.
This is my code so far:

...
// startOfDay and endOfDay are unix timestamp
startOfDay = parseInt('1395176400');
endOfDay = parseInt('1395262799'); 

var allSales = Sale.all().filter("created_at", '>', startOfDay)
  .and("created_at", '<', endOfDay) // It gives error here : TypeError: Object created_at has no method 'toUniqueString' persistence.js:1326:64)

allSales.list(function (results) {
   // compute results
}
...

When I remove the 'and' filter, I get some results but not the wanted ones.

Any help would be great.

Thanks. rvkone

Zef Hemel

unread,
Mar 21, 2014, 10:16:20 AM3/21/14
to persis...@googlegroups.com
From the top of my head .and() takes a filter object instance as a single argument, not three arguments like here. However, I'd say that if you just replace ".and" with ".filter" in your existing code (so two filter calls), you'd get what you're after.

-- Zef


--
You received this message because you are subscribed to the Google Groups "persistence.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to persistencej...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rvkone

unread,
Mar 21, 2014, 2:28:10 PM3/21/14
to persis...@googlegroups.com
That does it. I chain two filter() call. Thanks.
Reply all
Reply to author
Forward
0 new messages