Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Don't fail when trying to remove an unsaved object #94

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
Contributor

dmathieu commented Jan 22, 2013

When trying to destroy an unsaved object (this happens in some of our tests), acts as paranoid tries to remove the object, and calls it's id for that with

Array(self.class.primary_key), Array(self.id)].transpose

As self.id is nil, transpose can't work because the array is missing an entry.
And we don't need to run any sql query to remove an object if nothing has been saved into the database yet.

avit commented Jan 23, 2013

Confirmed, I'm seeing this problem here too. This pull request fixes it. 👍

Problem appears as:

Exception: IndexError: element size differs (0 should be 1)
--
0: /var/lib/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:206:in `rescue in transaction'
1: /var/lib/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:180:in `transaction'
2: /var/lib/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction'
3: /var/lib/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/associations/has_one_association.rb:14:in `replace'
4: /var/lib/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/associations/singular_association.rb:17:in `writer'

Me too.

kuboon commented Feb 5, 2013

how about destroy! method?

Contributor

dmathieu commented Feb 5, 2013

@kuboon: the destroy! method has been implemented only in rails 4. This pull request has no meaning to adding the support of rails master.

@chuckg chuckg closed this in aa2f9c4 Feb 28, 2013

@avit avit referenced this pull request May 22, 2013

Closed

Release 0.4.2 with fixes #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment