Query with RegExp and Array - regex

I have a class Post, with the following scope:
scope :by_tag, ->(tag){ where(:desc => /##{Regexp.escape(tag)}/) }
It works very well with one tags, but I can't make it work with various tags.
For example: I cant make it give me the posts tagged with #rails AND #regexp.
With criteria union I can make it return me the posts tagged with #rails OR #regexp.
How can I get it to work? I'm using mongoid, btw.
Thanks in advance.
Just fount that is not an OR. What happens is that the second time I call by_tag, it overrides the previous. I believe that's because it's the same property.
Someone know how to fix this? Thanks

Regexp queries tend to be really slow. Instead, store an array of tags and use $in to query the array.
With Mongoid 2.x use all_in
scope :by_tags, ->(*tags) { all_in(tags: *tags) }
With Mongoid 3 use all merge strategy
scope :by_tags, ->(*tags) { all(tags: *tags) }

Related

Can't access array element in HTMLBars template

As I understand it you should be able to access array elments via {{array.[0].something}}.
I am trying to use this but it is not working. In my case, claims is an async relationship of invoice.
{{invoice.claims.length}} //Returns "1" as expected
All these are blank
{{invoice.claims.[0]}}
{{invoice.claims.[0].claimNumber}}
{{invoice.claims.content.[0]}}
{{invoice.claims.content.[0].claimNumber}}
I can see the claim has been downloaded in ember-inspector but for some reason the binding has not worked.
Update
I got it working using the following
{{invoice.claims.firstObject.claimNumber}}
Still interested why the above works but {{invoice.claims.[0].claimNumber}} does not though.
Yes, it's is possible to access the elements of an array through handlebars like you have described. Here's a Twiddle demonstrating it.
The problem is in another part of your code. Provide more information to see where it can be.

How to specify delimiter for list.each function in ColdFusion 11?

I have adopted the CFScript syntax for most of the work with ColdFusion now, since with the new version of ColdFusion v11(codenamed Splender), almost all the short-comings of the script style syntax has been given serious thoughts. Thought suprisingly, I came across a requirement where I needed to iterate throught the list with variable delimiter. So I choose the list.each function in CF11 and not any other option would do since I also need the current index value along the way as well.
list.each(function(element,index,list){
writeOutput("#index#:#element#;");
}, ";")
The problem is that this function surprisingly does not seem to support a custom delimiter.
To save the time, I would like to mention that I already tried the for (element in...) with a count variable for my needs.
var idx=1;
for (element in "a,b,c,d,e"){
writeOutput(element);
LOCAL.idx++;
}
But I would appreciate some help with the original list.each function in CF11, is it even possible somehow to implement? or is it what I think a shortcoming.
I'm not using CF11, but i would point you to this bug report, which seems to say the HF3 does exactly what you want.
If that doesn't work, or in the meantime, you could convert it to an array and use ArrayEach().

how to load data to recursive dataView in extjs?

I have a recursive template.
new Ext.XTemplate(
'<tpl for="."><div>'+
'<div class="select">{text}</div>'+
'{[this.putChildren(values)]}'+
' </div></tpl>'
,
{
putChildren:function(values){
if(values.children){
Ext.each(values.children,function(child,index,arr){
return this.apply(values.children);
}
})
I set itemSelector:'select'
The thing is that when I load the data I get an error "records[i] is undefined" and when I set a listener the event is fired on every click but I get item=undefined on every node except the root.
I cant set a treeStore because dataview only excepts store or jsonstore. (maybe I'm doing something wrong?)
so I have a simple question how can I draw a tree using data view and a store?
I couldn't find any good recourse for this...
actually I have a template like this
http://www.youtube.com/watch?v=UhBjMws1H10&t=35m52s
I just cant load the data correctly...
do I need Store or TreeStore or something else?
thnx in advance
So why not use tree Panel?
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.tree.Panel
Have you ever solved this problem? Having the exact same issue. Although I haven't spent a lot of time with it for now.
Maybe it's useful for you to iterate directly through the children.
So, instead of
<tpl for=".">
i think you can directly use
<tpl for="children">
This makes it possible to use values as a variable already for each child.

WhereExpression method not found in SubSonic 3.0.0.4?

This is my first ever post on any forum, so excuse my etiquette.
Im using SubSonic 3.0.0.4 and was trying to concat a Fluent Query using ActiveRecord, I want to be able to use the WhereExpression method of SqlQuery to start adding a list of 'OR' statements with brackets round, to exclude the list from other constraints E.g.
var qry =
db.Select.From<DocumentHeader>();
qry.WhereExpression(DocumentHeadersTable.InvoiceNoColumn).Like(myList.Items[0]);
for (Int32 i = 1, n = myList.Items.Count; i < n; i++) {
qry.Or(DocumentHeadersTable.InvoiceNoColumn).Like(myList.Items[i]);
}
qry.CloseExpression();
There is more to it than this but this is a rough example. Searching on the web and looking at the Fluent Query page of SubSonic it suggests that the method WhereExpression does exist, but looking at the Intellisense and then in the source code downloaded from the GitHub, I could only find a Property not a Method. I have managed to do a workaround for the above problem, but the WhereExpression would be useful.
So after all that my question is, has this method been removed? or its usage changed? Or most likely Im being stupid and looking in the wrong place?
Thanks in advance.
Lee
Apparently, the WhereExpression got another implementation due to a massive addition of LINQ support in the version 3.0, so just use the Where method instead.

Need Help Understanding Doctrine 2's ArrayCollection::clear()

I just don't really get this part
Say you clear a collection of tags by
calling $post->getTags()->clear(); and
then call $post->getTags()->add($tag).
This will not recognize tag being
already added before and issue two
database calls.
What 2 database calls will be issued? Delete all tags of the post then add one? Thats what I'd expect? Or will it be something else?
Did you try to call after the clear?
$entityManager->flush();
If this don't help try to remove one by one in foreach.