-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
FindFirst() might not work correctly #1018
Comments
Hi @gillde |
We cannot reproduce this behaviour, so closing. Please reopen if there is any new information about this. |
I'd like to reopen this. I found a way to reproduce this behaviour. Game: public class Game extends RealmObject
{
@PrimaryKey
private long id;
private long levelId;
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public long getLevelId()
{
return levelId;
}
public void setLevelId(long levelId)
{
this.levelId = levelId;
}
} GameState: public class GameState extends RealmObject
{
@PrimaryKey
private long id;
private long levelId;
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public long getLevelId()
{
return levelId;
}
public void setLevelId(long levelId)
{
this.levelId = levelId;
}
} MainActivity: Realm realm = Realm.getInstance(this);
realm.beginTransaction();
for(int i = 0; i < 10; i++)
{
Game game = new Game();
game.setId(i);
game.setLevelId(1);
realm.copyToRealmOrUpdate(game);
}
realm.commitTransaction();
realm.beginTransaction();
for(int i = 11; i < 20; i++)
{
Game game = new Game();
game.setId(i);
game.setLevelId(2);
realm.copyToRealmOrUpdate(game);
}
realm.commitTransaction();
RealmResults<Game> games = realm.where(Game.class).equalTo("levelId", 2).findAll();
RealmResults<GameState> gameStates = realm.where(GameState.class).equalTo("levelId", 2).findAll();
if(gameStates.size() < games.size())
{
for(Game game : games)
{
if(gameStates.where().equalTo("id", game.getId()).count() == 0)
{
realm.beginTransaction();
GameState stateGame = new GameState();
stateGame.setId(game.getId());
stateGame.setLevelId(game.getLevelId());
realm.copyToRealm(stateGame);
realm.commitTransaction();
}
}
}
gameStates = realm.where(GameState.class).equalTo("levelId", 2).findAll();
for(Game game : games)
{
GameState gameState = gameStates.where().equalTo("id", game.getId()).findFirst();
GameState gameState1 = gameStates.where().equalTo("id", game.getId()).findAll().first();
Log.d("TAG", "gameState: " + gameState + " | gameState1: " + gameState1);
} These are the results:
I hope this is enough information to find the problem. Nasty one to reproduce, but this particular case went wrong with my game. |
Hi @kevinvanmierlo |
Hi @kevinvanmierlo
Which should be correct. What version of Realm are you testing against? |
@cmelchior I'm using 0.80.3. I always test on Genymotion with lollipop. The weird thing is when I just tested it on my normal device it worked as expected while on Genymotion it gives back the wrong result. |
That sounds really odd, because I usually run these tests on the same setup. Can you possibly share the full sample project so I am absolutely sure I don't do anything different on my end? |
@cmelchior sure! I'm grabbing some lunch first and then I'll share it with you. |
@cmelchior I pushed the sample project to GitHub. You can find it here. |
This is really strange. I cannot reproduce your behaviour even when using the same project on Genymotion 2.4 with a Nexus 5 - 5.1.0 emulator. Do you only see this error on Genymotion but not on your device / Android emulator? |
Actually I'm using the Google Nexus 5 - 5.0.0 - API 21 Genymotion. So perhaps that's the difference. The system has 4 processors and the Base Memory is 2048 MB. I don't see the error on my device (5.0) or emulator(5.0.1). I don't really know why the error only appears on this specific configuration. Edit: The error also doesn't show on my Genymotion 2.4 with Nexus 5 - 5.1.0 emulator |
Hi @kevinvanmierlo |
@cmelchior After deleting and creating a new one, this also worked. Very weird that it happened though. Thanks for the quick responses! |
Yes, it is a bit strange. It might be a bit late, but if you still has a copy of a Realm file where this error occurred it would be nice to see it. Perhaps we can see what was wrong with it? |
@cmelchior I deleted the emulator, so no way of getting that back. I should've backed it up. I'll see if I can recreate the error somehow. |
Thanks. If you manage to reproduce it please send the file to [email protected]. In the meantime I'll close this issue. |
Copy from: #826 (comment)
I see that this was merged into master in february. But I think I am still have issues related to different results from findFirst() and findAll().first()
I have a RealmResults which I further want to query: mAllUsersForCompany is of type RealmResults:
The following works. It gives me a user whos name has length of three and who was in the mAllUsersForCompany list:
mAllUsersForCompany.where().equalTo("nameLength", 3).findAll().first()
But the following seems to completely ignore the additional equalTo constraint and gives me a user which has namelength != 3
mAllUsersForCompany.where().equalTo("nameLength", 3).findFirst()
The text was updated successfully, but these errors were encountered: