Ruby on Rails Sunday, February 27, 2011

I need to write a Mongoid criteria

criteria.where(:tags => myStruct ).to_a

in which myStruct will have this structure { "$in" =>
[check_tags[0]], "$in" =>[check_tags[1]] , .. }
built from a check_tags Array

it's a sequence of .in criteria
I am checking if ALL of the elements of check_tags[] are included in a
Mongoid record Array field :tags

the simplest Mongoid criteria:
criteria.in(:tags => tags)
just perform a checking on ANY element included, not ALL

On 27 fév, 21:49, Frederick Cheung <frederick.che...@gmail.com> wrote:
> On Feb 27, 7:56 pm, Erwin <yves_duf...@mac.com> wrote:
>
> > this is to be used with MongoID as a criteria
>
> > criteria.where(:tags => { "$in" => [tags[0]], "$in"
> > =>[tags[1]] }).to_a
>
> > any suggestion with json structure ?
>
> You can't repeat keys in a json hash either. What are you actually
> trying to do?
>
> Fred
>
>
>
>
>
>
>
>
>
> > On 27 fév, 19:47, Frederick Cheung <frederick.che...@gmail.com> wrote:
>
> > > On Feb 27, 6:29 pm, Erwin <yves_duf...@mac.com> wrote:
>
> > > > given an Arra tags[]
>
> > > > I need to produce a resulting Hash as following ..
>
> > > > { "$in" => [tags[0]], "$in" =>[tags[1], ...}
>
> > > > in which the key should be always the same and the value being an
> > > > Array
>
> > > By definition, a hash stores a single value for a given key. The
> > > closest you'll get is to make the value an array of all the things for
> > > the key in question.
>
> > > Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment