Owww
I think that I found the problem...
It find itself again..
I need to change database after find the same id, but if I do this will
have 2 records with the same position, then I need to improve the search
to don''t find the self id, correctly?
Sorry,
Pedro
Pedro Valentini escreveu:
>
> Hello,
>
> It is a piece of my *reorder* funcion in Media model:
> case act
> when "up"
> other =
> Media.find_by_position_and_parent_id(self.position-1,self.parent_id)
> if nil != other
> other.reorder(''down'')
> end
> self.position = self.position - 1
> when "down"
> other =
> Media.find_by_position_and_parent_id(self.position+1,self.parent_id)
> if nil != other
> other.reorder(''up'')
> end
> self.position = self.position + 1
> when "top"
> other =
> Media.find_by_position_and_parent_id(0,self.parent_id)
> if nil != other
> other.reorder(''down'')
> end
> self.position = 0
> when "bottom"
> other =
> Media.find_by_position_and_parent_id(999,self.parent_id)
> if nil != other
> other.reorder(''up'')
> end
> self.position = 999
> else
> render_text "Illegal action to reorder."
> end
> Looks fine for me, but it is a loop, and the error is:
>
>
> ActiveRecord::StatementInvalid in Media#reorder
>
> stack level too deep: SELECT * FROM medias WHERE position = 1 AND
> parent_id = 99 LIMIT 1
>
>|/app/models/media.rb:115:in `reorder''
>/app/models/media.rb:111:in `reorder''
>/app/models/media.rb:117:in `reorder''
>||/app/models/media.rb:115:in `reorder''
>||/app/models/media.rb:117:in `reorder''
>||/app/models/media.rb:115:in `reorder''|
>|...
>...
>|
>
> Do you know what can be wrong?
>
> Thank you.
>
>--
>
>Pedro C. Valentini
>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org
>+55 (21) 8708-8035
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Rails mailing list
>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>------------------------------------------------------------------------
>
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.0.308 / Virus Database: 266.9.17 - Release Date: 19/4/2005
>
>
--
Pedro C. Valentini
pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org
+55 (21) 8708-8035