[Rails] Re: activerecord get next element

2009-09-23 Thread Colin Law
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

[Rails] Re: activerecord get next element

2009-09-23 Thread mickeyben
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,

[Rails] Re: activerecord get next element

2009-09-23 Thread Colin Law
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

[Rails] Re: activerecord get next element

2009-09-23 Thread Rob Biedenharn
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

[Rails] Re: activerecord get next element

2009-09-23 Thread mickeyben
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

[Rails] Re: activerecord get next element

2009-09-23 Thread Marnen Laibow-Koser
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

[Rails] Re: activerecord get next element

2009-09-23 Thread Tim Lowrimore
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|

[Rails] Re: activerecord get next element

2009-09-23 Thread Tim Lowrimore
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

[Rails] Re: activerecord get next element

2009-09-23 Thread mickeyben
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