2009/9/23 Bensoussan Michael pad...@gmail.com:
Hi,
How would you get an SQL element, the next one and the previous one,
but the definition of a next/previous element is not dependant only of
his id but also of a status,
exemple :
id status
1 true
2 false
3 true
Here the next element
yes but that doesnt resolve my problem (I think), I don't want to
select all the database, otherwise I just need to filter by status an
order by id, I just want this 3 results :-/
On Sep 23, 2:38 pm, Colin Law clan...@googlemail.com wrote:
2009/9/23 Bensoussan Michael pad...@gmail.com:
Hi,
2009/9/23 mickeyben pad...@gmail.com:
yes but that doesnt resolve my problem (I think), I don't want to
select all the database, otherwise I just need to filter by status an
order by id, I just want this 3 results :-/
Do you mean that you know the id of a record, and you have a defined
sort
On Sep 23, 2009, at 7:49 AM, mickeyben wrote:
On Sep 23, 2:38 pm, Colin Law clan...@googlemail.com wrote:
2009/9/23 Bensoussan Michael pad...@gmail.com:
Hi,
How would you get an SQL element, the next one and the previous one,
but the definition of a next/previous element is not dependant
thanks colin and rob, that's approximately what I have so far,
I was hoping a solution to do it in one request :-/
On Sep 23, 3:08 pm, Rob Biedenharn r...@agileconsultingllc.com
wrote:
On Sep 23, 2009, at 7:49 AM, mickeyben wrote:
On Sep 23, 2:38 pm, Colin Law clan...@googlemail.com
Mike Mickey wrote:
thanks colin and rob, that's approximately what I have so far,
I was hoping a solution to do it in one request :-/
The simplest way would be to use UNION on the two queries. You could
also use subquery syntax to munge the criteria.
Best,
--
Marnen Laibow-Koser
Better yet. Take these conditions and apply each as a named scope. Then,
by chaining the calls you'll get everything in one nice little query. So
for example (assuming a default order of: id ASC):
In your model (lets call it Foo):
named_scope :for_status, lambda { |status|
Actually the calls should look like this:
previous = Foo.for_status(true).find_previous(3).last
next = Foo.for_status(true).find_subsequent(1).first
So, the .last and .first calls were transposed.
Cheers,
Tim
On Wed, Sep 23, 2009 at 10:05 AM, Tim Lowrimore tlowrim...@gmail.comwrote:
Better
nice one !
Thanks
On Sep 23, 6:26 pm, Tim Lowrimore tlowrim...@gmail.com wrote:
Actually the calls should look like this:
previous = Foo.for_status(true).find_previous(3).last
next = Foo.for_status(true).find_subsequent(1).first
So, the .last and .first calls were transposed.
Cheers,
Tim
9 matches
Mail list logo