Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
before_destroy
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ivan  
View profile   Translate to Translated (View Original)
 More options Nov 11, 10:52 am
From: Ivan <ihschus...@gmail.com>
Date: Wed, 11 Nov 2009 07:52:18 -0800 (PST)
Local: Wed, Nov 11 2009 10:52 am
Subject: before_destroy
Pessoas.

Eu preciso consistir a existência de registros "filhos" para poder
efetuar uma exclusão. Se houver "filhos", não posso excluir.
Para isto utilizei o callback "before_destroy", da seguinte forma.

before_destroy :tem_filhos?

Pela documentação, se ":tem_filhos?" retornar "false" o "destroy"
deveria ser abortado e um rollback deveria ser disparado.
Infelizmente não é o que está acontecendo. Cheguei a forçar o retorno
do false (como situação única) e, mesmo assim, o "destroy" no registro
"pai" é executado.

Estou fazendo correto?
Como fazer para evitar que um registro "pai" seja excluído se houver
"filhos"?

Abs,

Ivan


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
G. Sobrinho  
View profile   Translate to Translated (View Original)
 More options Nov 11, 11:00 am
From: "G. Sobrinho" <gabriel.sobri...@gmail.com>
Date: Wed, 11 Nov 2009 14:00:03 -0200
Local: Wed, Nov 11 2009 11:00 am
Subject: Re: [rails-br] before_destroy

http://github.com/scambra/dependent_protect ;)

2009/11/11 Ivan <ihschus...@gmail.com>

--
Cordialmente,

Gabriel Sobrinho
Diretor de desenvolvimento

Hite - Comunicação Digital e Mídia Interativa
http://www.hite.com.br/

+55 31 8775 8378


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ivan Schuster  
View profile   Translate to Translated (View Original)
 More options Nov 11, 11:23 am
From: Ivan Schuster <ihschus...@gmail.com>
Date: Wed, 11 Nov 2009 14:23:27 -0200
Local: Wed, Nov 11 2009 11:23 am
Subject: Re: [rails-br] Re: before_destroy

Obrigado Sobrinho, mas e quanto ao que estou fazendo, está errado ou não
está funcionando como deveria?
Saberias me dizer?

Abs,

Ivan

2009/11/11 G. Sobrinho <gabriel.sobri...@gmail.com>


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
wurtog  
View profile   Translate to Translated (View Original)
 More options Nov 11, 11:48 am
From: wurtog <wur...@gmail.com>
Date: Wed, 11 Nov 2009 14:48:05 -0200
Local: Wed, Nov 11 2009 11:48 am
Subject: Re: [rails-br] before_destroy
Ivan,

No seu modelo você deve fazer um overload do método before_destroy
(isto é, criar um método chamado before_destroy) dentro do seu modelo.
Se esse método retornar falso, aí sim, a ação é cancelada.

Abraços!

2009/11/11 Ivan <ihschus...@gmail.com>:

--
wurtog
http://twitter.com/wurtog

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ivan Schuster  
View profile   Translate to Translated (View Original)
 More options Nov 12, 6:17 pm
From: Ivan Schuster <ihschus...@gmail.com>
Date: Thu, 12 Nov 2009 21:17:59 -0200
Local: Thurs, Nov 12 2009 6:17 pm
Subject: Re: [rails-br] Re: before_destroy

Minhas conclusões:

1) Tanto a utilização do callback "before_destroy", quanto fazer um overload
do método "before_destroy", funcionam. Isto é, retornando "false" o
"destroy" é abortado.

2) Onde, então, está o problema? Se na declaração do "has_many" for
utilizada a opçao ":dependent => destroy" em relação ao filho - o que,
convenhamos, não faz sentido, pois é justamente o que se quer evitar ;-) -
os registros do filho serão excluídos antes da validação. Isto é, o
"dependent => :destroy" é executado antes do "before_save". Aí, quando o
"before_save" é executado, não há mais registros filhos, pois já foram
excluídos.

3) Mas e se eu quiser usar o ":dependent : => destroy" junto com o
"before_destroy", tem como? Tem. Simplesmente declare o "before_destroy"
ANTES do "has_many". Como está bem descrito na documentação, o Rails executa
os callbacks na ordem em que aparecem.

Obrigado à todos.

Abs,

Ivan

2009/11/11 wurtog <wur...@gmail.com>


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google