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

store.find not working as expected #42

Open
erochaamorim opened this issue Aug 8, 2015 · 1 comment
Open

store.find not working as expected #42

erochaamorim opened this issue Aug 8, 2015 · 1 comment

Comments

@erochaamorim
Copy link

Hello, how are you doing?

I started using angular-indexedDB today, but I'm having dificulties working with the store.find() function.

You see, I'm defining a store like this:

db.createObjectStore('campaigns', {keyPath: 'id', autoIncrement: true});

... and I'm able to have insert() and getAll() work as I expected. But, when I try to use the store.find(), like this:

store.find($state.params.campaign_id).then(function(campaign) {
  $scope.campaign = campaign;
});

... it simply, doesn't works.

I already have certified (through simple debugging with console.log) that the $state.params are well-formed, and correct, also that there's an entry which possesses a property id equal to the parameter, when the function is called.

Could it be that the store.find() function does not behaves properly when the store have a keyPath and a keyGenerator (autoIncrement) ?

--UPDATE 09/08/2015--

Greetings.

I was able to make it work as I wanted, but I had to pass the entire campaign object through the params, instead of only the id:

store.find($state.params.campaign.id).then(function(campaign) {
  $scope.campaign = campaign;

It seems the store.find() function does not performs a deep comparison between the store.key and the value passed as argument, what would explain why passing a by-copy value (instead of the actual reference) does not works.

Also I'm not sure if the store.find() function's key comparison takes data type (primitives, like String, Number, etc) into account.

@bramski
Copy link
Owner

bramski commented Oct 14, 2015

My apologies for taking so long in getting back to you.

I don't think I quite understand your difficulty.

Find is really really simple...
https://github.com/bramski/angular-indexedDB/blob/master/src/angular-indexed-db.coffee#L421

It just issues a "get" with the identifier you requeested against the underlying store. I suspect your problem is really simple, like using a string for the identifier instead of turning it into an integer as your object actually refers to it. Make sure your types are correct is my suggestion.

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

2 participants