Comments (6)
Duplicated. Kinda odd as well. Looks like the placement is in the wrong place as you mentioned.
This predicate as suggest in the initial report works and has the correct placement for @allvalues
let subquery = NSPredicate(format: "SUBQUERY(flags.@allValues, $flag, $flag.isLoud == true).@count == 3", "")
from realm-swift.
➤ PM Bot commented:
Jira ticket: RCOCOA-2412
from realm-swift.
Updated the issue with a more concise summary.
An Aside:
It would be nice if the Realm Query Syntax API were smart enough to add == true
when required. My initial query was:
($0.flags.values.isLoud).count > 0
The compiler showed no errors here, but at runtime the resulting predicate failed to parse and it took me a minute to realize why, since the other issue with @allValues
misplacement happened simultaneously. I think most Swift developers don't write == true
when evaluating a boolean, so that habit carries over into the query syntax and it'll bite you. If possible, Realm should consider adding handling for that or a more explicit warning about the footgun.
from realm-swift.
I am not exactly sure what the expected result is so let me take a crack at it.
Looking at the code - it appears the goal is to return all Bar objects where the flags Map property contains isLoud == true.
Allow me to set up a test case
let f0 = Flag()
f0.isLoud = false
let f1 = Flag()
f1.isLoud = true
let f2 = Flag()
f2.isLoud = false
let f3 = Flag()
f3.isLoud = false
let bar0 = Bar()
bar0.flags["a"] = f0
bar0.flags["b"] = f1 //f1.isLoud == true
let bar1 = Bar()
bar1.flags["c"] = f2
bar1.flags["d"] = f3
try! realm.write {
realm.add(bar0)
realm.add(bar1)
}
So the result here is that bar0's flags property "b" key contains value f1 where isLoud
is true
but bar1 (which contains f2 and f3, has no flags property where isLoud
is true
.
The goal is return bar0 since it has at least one flags
property where isLoud == true
Doesn't this query solve that?
let results = realm.objects(Bar.self).where { $0.flags.values.isLoud == true }
print(results)
and the result is bar 0
Results<Bar> <0x151e3bd40> (
[0] Bar {
flags = Map<string, Flag> <0x6000014b5800> (
[a]: Flag {
isLoud = 0;
},
[b]: Flag {
isLoud = 1;
}
);
}
)
likewise if we change f2, which is in bar1
to have isLoud
set to true, both bar0
and bar1
are returned.
let f2 = Flag()
f2.isLoud = true
I think the .count
is extraneous in this case as any flags
within a bar
where isLoud == true
will be returned. e.g. if the count was 0, it would not be returned because there is no isLoud == true
.
Let me know if the desired result is different than my guess.
from realm-swift.
Perhaps I've not been clear.
Realm translates .where{}
clauses into NSPredicate
objects on-the-fly. It would appear that this translation layer is placing @allValues
in the wrong spot.
Whether .count > 0
is strictly necessary is not the point. The point is that given the where{}
clause above (which IS valid), the translation-on-the-fly layer is producing an invalid NSPredicate
.
In other words, adding .count > 0
should not cause the translation layer to place @allValues
where it is when a SUBQUERY
is written by that translation layer.
(In my actual app, there's several parts to this query. I've narrowed it down to a simplified example.)
from realm-swift.
@Jaycyn here's another way to see the problem: suppose we wanted to fetch all Bar
objects that have exactly 3 loud flags in their Map property.
Now .count == 3
is needed and you should be able to reproduce the bug I'm reporting here.
from realm-swift.
Related Issues (20)
- Is it possible to fully deallocate the Memory used by Realm HOT 4
- Doesn't Map value type work at all? HOT 4
- Multiple methods named 'initWithValue:' found with mismatched result, parameter type or attributes v10.50.1 HOT 3
- ObjectId does not conform to SortableType - sorted(by:ascending:) not working as expected HOT 3
- Namespace DYLD, Code 1 Library missing HOT 2
- RealmSwift Crashing on Xcode 16 beta 2 when used in XCFramework as Dependency HOT 2
- Support "Cascading/Inheritable" Writes HOT 16
- Realm crash when accessing PersistableEnum HOT 13
- 极个别用户数据会莫名删除清空 HOT 2
- Migration strange behavior when schema version resets to zero HOT 12
- XCFramework compitability issue with Xcode HOT 2
- Ensure Migration.enumerateObjects(ofType:_:) consistently uses property mappings HOT 5
- Migrate Sync tests to use Basaas HOT 1
- Schema version is increased before Realm is initialized causing migration block to not run HOT 6
- N5realm18MultipleSyncAgentsE crash on start HOT 1
- realm::util::File::barrier() HOT 8
- Unit Test: Undefined symbol: _$s10RealmSwift0A0V13ConfigurationV07defaultC0AEvgZ HOT 3
- Allow KVC Collection Operators in Sort Descriptors HOT 7
- 'Realm accessed from incorrect thread.' in iOS 18 while in iOS 17 no issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-swift.