Hello,
how can I check if a destroy was successful?
Is the object only frozen if deleted or do I have to do an additional
find to see if there is a record left?
What happens if an after_destroy callback returns false? Is there always
a rollback?
Markus
On Saturday, July 15, 2006, at 11:07 PM, Markus K. wrote:
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
You should be able to ensure a destroy works with the proper tests, but
if you really insist on wearing belts and suspenders you can do this.
Item.destroy(params[:id])
if Item.exists?(params[:id])
not destroyed
else
destroyed
end
Assuming it exists in the first place.
_Kevin
www.sciwerks.com
Kevin O. wrote on 16.07.2006 00:20:
On Saturday, July 15, 2006, at 11:07 PM, Markus K. wrote:
Hello,
how can I check if a destroy was successful?
Is the object only frozen if deleted or do I have to do an additional
find to see if there is a record left?
What happens if an after_destroy callback returns false? Is there always
a rollback?
?
[…]
You should be able to ensure a destroy works with the proper tests, but
if you really insist on wearing belts and suspenders you can do this.
Item.destroy(params[:id])
if Item.exists?(params[:id])
What happens if the DB is not available during executing the destroy and
exists? (“Server shutdown in progress”, “Broken pipe”, “Lost connection
to server during query”, “server has gone away”)
How is this handled by AR?
Markus
On Sunday, July 16, 2006, at 1:04 AM, Markus K. wrote:
?
How is this handled by AR?
Markus
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
‘exists?’ will query the database to see if that record number exists,
so if the database is down it will raise an exception, I think.
_Kevin
www.sciwerks.com
On Sunday, July 16, 2006, at 12:13 PM, Markus K. wrote:
so if the database is down it will raise an exception, I think.
[…]
Which exception. I can’t find any documentation to exceptions of AR.
Markus
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Try running your application with your database turned off and see what
happens.
_Kevin
www.sciwerks.com
On Sunday, July 16, 2006, at 12:28 PM, Kevin O. wrote:
[…]
Rails mailing list
Posted with http://DevLists.com. Sign up and save your mailbox.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
I get this exception when I do it.
‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
(2)’
_Kevin
www.sciwerks.com
Kevin O. wrote on 16.07.2006 14:36:
[…]
‘exists?’ will query the database to see if that record number exists,
so if the database is down it will raise an exception, I think.
[…]
Which exception. I can’t find any documentation to exceptions of AR.
[…]
I get this exception when I do it.
‘Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)’
Is the exception from destroy or exists?()
I think it’s not coming from exists?() because it rescues from
exceptions and returns false.
Is there really no documentation of the exception classes and how they
are used in AR? It is horror to go through the source to find
possibilities of exceptions.
Kevin, thanks for your help.
Kevin O. wrote on 16.07.2006 01:15:
On Sunday, July 16, 2006, at 1:04 AM, Markus K. wrote:
[…]
What happens if the DB is not available during executing the destroy and
exists? (“Server shutdown in progress”, “Broken pipe”, “Lost connection
to server during query”, “server has gone away”)
How is this handled by AR?
[…]
‘exists?’ will query the database to see if that record number exists,
so if the database is down it will raise an exception, I think.
[…]
Which exception. I can’t find any documentation to exceptions of AR.
Markus
Is there really no documentation of the exception classes and how they
are used in AR? It is horror to go through the source to find
possibilities of exceptions.
http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active_record/base.rb
All the ActiveRecord exceptions are defined at the top.
Rick O. wrote on 16.07.2006 19:00:
Is there really no documentation of the exception classes and how they
are used in AR? It is horror to go through the source to find
possibilities of exceptions.
http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active_record/base.rb
All the ActiveRecord exceptions are defined at the top.
I know but there is no doc and I think 99% of methods have no
information which exceptions they could raise and because of which
situation. Without such information it’s nearly impossible to use
exceptions for error detection and rescue handling.
It shouldn’t be an exception to describe exceptions ;(
I know but there is no doc and I think 99% of methods have no
information which exceptions they could raise and because of which
situation. Without such information it’s nearly impossible to use
exceptions for error detection and rescue handling.
It shouldn’t be an exception to describe exceptions ;(
Doc patches are excepted. har
On Sunday, July 16, 2006, at 4:46 PM, Markus K. wrote:
to server during query", “server has gone away”)
I get this exception when I do it.
possibilities of exceptions.
Kevin, thanks for your help.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
I generated this exception by turning off mysql and trying to do
anything with my rails app.
The problem you are much more likely to encounter is if a record is
destoyed by another user before your request is processed. You could
check your params[:id] for a valid record number before proceeding with
the destroy. In fact, I use a before filter for this very thing.
At least you can do something like this…
def destroy
begin
Item.find(params[:id]).destroy
rescue
an exception was raised… db down, record not found, etc…
end
end
_Kevin
www.sciwerks.com
This might be fruitful (I’m sure there’s a better regex for this):
find vendor/rails/activerecord -name *.rb -exec grep -n “[^_]raise[ \t]”
‘{}’ ; -print
Partial results:
activerecord/lib/active_record/associations/association_proxy.rb
983: raise ArgumentError, ‘:dependent and
:exclusively_dependent are mutually exclusive options. You may specify
one or the other.’
1010: raise ArgumentError, ‘The :dependent option expects
either :destroy, :delete_all, or :nullify’
1023: raise ArgumentError, “The :dependent option expects
either :destroy or :nullify.”
1285: raise ConfigurationError, “Association named ‘#{
associations }’ was not found; perhaps you misspelled it?”