Writing DM queries using newer 1.9+ symbol format, how?

22 views
Skip to first unread message

Gus Shotz

unread,
Apr 3, 2013, 8:50:30 PM4/3/13
to datam...@googlegroups.com
How would I write zoo.all(:population.gte => 100, :staff.gt => 2) using the newer symbol: format? I was hoping I could do zoo.all(population: >= 100, staff: > 2) but it doesn't work.

Chris Corbyn

unread,
Apr 3, 2013, 9:08:40 PM4/3/13
to datam...@googlegroups.com
That syntax is not a new Symbol format, it's a new Hash syntax, where the keys are Symbols. You can't use that with DataMapper, since :staff.gt is not a Symbol itself. You can mix the two syntaxes if you want though.

Il giorno 04/apr/2013, alle ore 11:50, Gus Shotz <guts...@gmail.com> ha scritto:

How would I write zoo.all(:population.gte => 100, :staff.gt => 2) using the newer symbol: format? I was hoping I could do zoo.all(population: >= 100, staff: > 2) but it doesn't work.

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datamapper+...@googlegroups.com.
To post to this group, send email to datam...@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

guts...@gmail.com

unread,
Apr 3, 2013, 9:17:24 PM4/3/13
to datam...@googlegroups.com
Ah, I see.

I did notice that zoo.all(population: (start..end)) is valid. I guess that's what you meant by "mix the two syntaxes."
You received this message because you are subscribed to a topic in the Google Groups "DataMapper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/datamapper/FDfepXSwXEU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to datamapper+...@googlegroups.com.

Ted Han

unread,
Apr 3, 2013, 9:45:42 PM4/3/13
to DataMapper
Not quite.  Datamapper does two things intelligently.  The first is that it infers what it's supposed to do based on the value of a property.

So when you say `People.all(age: (start..end))` it'll infer that you want to look for ages within that range.

Additionally DataMapper allows you to use structured keys to indicate other relationships.  Early in DataMapper's life, back when it was still okay to patch core classes, DataMapper by default added some methods on Symbol that allowed you to say things like :age.gt and have that Do The Right Thing.

That's fallen out of vogue directly, but you can still use structured keys as strings.  So you should be able to say `People.all("age.gt": 15)` and it'll look for everyone older than 15.

guts...@gmail.com

unread,
Apr 3, 2013, 9:50:00 PM4/3/13
to datam...@googlegroups.com
So :age.gt doesn't work anymore? Is there a more up-to-date documentation than the DataMapper.org site?

Thanks for the help.
Reply all
Reply to author
Forward
0 new messages