Hi Norbert, this reminds me of something IIRC that Alan Knight did in TopLink, a commercial OR mapping tool. Alan allowed one to write queries in conventional Smalltalk such as db select: [:obj| obj name = 'foo' or: [obj feature isSomething]] but under the covers compiling this block into a query that the database could execute by evaluating the block once, passing in a "compiling" object that implements doesNotUnderstand: to catch the messages sent in the block. That technique could work in this context and avoid introducing the (excuse me for saying, /horrible/) tuple syntax. Eliot (phone) On Jan 5, 2015, at 4:41 AM, Norbert Hartl <norbert@hartl.name> wrote:
Am 05.01.2015 um 04:59 schrieb Yanni Chiu <yanni@rogers.com>:
On Jan 4, 2015, at 4:38 AM, Norbert Hartl <norbert@hartl.name> wrote:
someCollection select: { '$or' -> { { 'name' -> { '$regex' -> 'test' . '$options' -> 'i' } asDictionary } asDictionary. { 'description' -> { '$regex' -> 'test' . '$options' -> 'i' } asDictionary } asDictionary } } asDictionary
That worked. I was close, but I was using $or: instead of $or, and I was missing one level of asDictionary.
Just for the archive, thereâs one more query I needed, which was to find an object based on itâs object id. I ended up using:
voyageId := Integer readFrom: (request at: #voyageId) base: 16. someModel := SomeModel selectOne: { '_id' -> (OID value: voyageId) } asDictionary.
This is a web app using Teapot and Mustache, so I write the voyageId out using:
self voyageId value printStringHex
Sounds cool. If you have anything to publish I'm interested what you've done. Especially if you have some nice tricks doing form handling in teapot.
Btw. for the archive. A common use case I encounter is to query objects that are being referenced by another object. It works like this
AnyClass>>#referencedBy: anObject ^ AnyClass selectMany: { 'reference.__id' -> anObject voyageId } asDictionary
Norbert