[Nitro] Complex selections

James Britt jamesUNDERBARb at neurogami.com
Tue Mar 22 21:48:11 EST 2005


I have an app (well, I'm learning Nitro/Og as I write it) that has a 
fairly simple object model.

A Resource object models a bookmark, a la del.icio.us, which has among 
its properties a set of Tag objects.  Tags are basically simple structs; 
the main property is the name.

I want to be able to select a set of resources that have one or more 
tags with a given name.

Some pseudo-code:
# assume tag_set is an array of tag names
rset   = []
  Resource.select { |r|
   tag_set.each { |t|
     rset  << r if r.tags.include? t
   }
}
rset.uniq!

Probably not the most efficient way to do this, and almost certainly not 
correct Og-speak.

In my first go-round with Rails (where I first implemented this), I did 
not find any nice Ruby-based way to do this, and ended up falling back 
on assorted SQL (and running into various issues with subselect and MySQL).

Is there some way to do this in Og without also having to hand-craft the 
SQL?  Is this sort of select just better done using in SQL?

Thanks,


James

-- 

http://www.ruby-doc.org
http://www.rubyxml.com
http://catapult.rubyforge.com
http://orbjson.rubyforge.com
http://ooo4r.rubyforge.com
http://www.jamesbritt.com



More information about the Nitro-general mailing list