http://wikipedlla.com/conditional_filters_on_a_sequel_model
Hi guys,
I'm having difficulty putting together a basic search facility for a
model using Sequel. I thought I could do something like this:
class Post lt; Sequel::Model(:posts)
end
Post.filter do
nbsp; if @criteria
nbsp;
searchset = Model.filter {:enabled = true}
if some condition
searchset = searchset.filter{:extra = false}
end
You can also do instead:
if some condition
searchset.filter!{:extra = false}
end
sharon
--~--~-~--~~~---~--~~
You received this message
On Sat, Feb 9, 2008 at 1:13 PM, Sharon Rosner [EMAIL PROTECTED] wrote:
searchset = Model.filter {:enabled = true}
if some condition
searchset = searchset.filter{:extra = false}
end
You can also do instead:
if some condition
searchset.filter!{:extra = false}
end
For some reason I can't use normal Ruby conditions within the block
I'm passing to Model.filter.
I.e. the following is falling over:
Post.filter do
if [EMAIL PROTECTED] use_title
:title.like [EMAIL PROTECTED]
end
end
It doesn't like multiple conditions AFAIK.
So i tried to get around
Thanks for the tip. I'm avoiding this approach as I have to combine
different filters depending on what's supplied, so I could potentially
have loads of permutations of the filter creation, which would be
ugly.
Unless of course you can keep adding to the same filter?
Kee
On Feb 6, 1:17 pm,
On Wed, Feb 6, 2008 at 6:01 AM, keeran [EMAIL PROTECTED] wrote:
Think I've found a solution, I didn't realise you could add additional
filters to an existing dataset...
So now I'm doing:
searchset = Model.filter {:enabled = true}
if some condition
searchset =
Hi guys,
I'm having difficulty putting together a basic search facility for a
model using Sequel. I thought I could do something like this:
class Post Sequel::Model(:posts)
end
Post.filter do
if @criteria
:title.like [EMAIL PROTECTED]
end
end
But this is falling over with :
Ah brilliant thanks :)
On Feb 5, 1:17 pm, Sharon Rosner [EMAIL PROTECTED] wrote:
ArgumentError: wrong number of arguments (2 for 1)
This is a bug. The Sequelizer code was missing support for conditional
filters (using if else statements). I'll push out a release with a fix in a
few
On Feb 5, 2008 9:40 AM, Sharon Rosner [EMAIL PROTECTED] wrote:
Should I use trunk from now on btw?
Using the trunk is generally OK and we try to make sure the specs all pass
before committing the trunk but on occasion an unexpected regression will
break through.
And from now on most