# One record too many stored, with NULL. Why?

**URL:** <https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417>\
**Category:** Rails\
**Created:** [November 18, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417 "2006-11-18T17:42:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 18, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417/1 "2006-11-18T17:42:55Z")

</div>

Hi, I have a form, that after submit saves data in 2 different tables.  
It works fine, only in the member-table there is an extra record added,  
each time the user submits data, with in the rubric\_idfield NULL. I  
checked the parsed data, and they are fine, no extra anything. Should  
be simple but I cannot pinpoint it. Please, if you could spare some  
time…

Code:

Action =  
Combination.transaction do  
@members.combination = @combination  
@combination.add\_rubrics(@rubrics)  
@combination.save  
@members.save  
end

add\_rubrics =

def add\_rubrics(rubrics)  
rubrics.items.each do |item|  
li = Member.new\_rubric(item)  
members \<\< li  
end  
end

new\_rubric(item)=

def self.new\_rubric(item)  
li = self.new  
li.rubric\_id = item.id  
li  
end  
I’m convinced it has to be here, but I don’t know why it happens.

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 18, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417/2 "2006-11-18T18:18:25Z")

</div>

Could it be that at the point at which this code runs one of the  
@rubrics has an item that has not been saved yet (and thus doesn not  
have an id) ?

Fred

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 18, 2006, 10:24pm UTC](https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417/3 "2006-11-18T22:24:26Z")

</div>

Have you checked by examining all of those objects in the debugger?

Fred

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 18, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417/4 "2006-11-18T22:49:32Z")

</div>

Yep.  
Iknow there must be a season for this extra record, and it’s the first  
I’ve ever seen this. I even restarted my working sytem a few times (Mac  
OSX 4.8; MAMP, Locomotive, Textmate), with no difference. That’s why  
I’m so… flabbergasted. (Like that word)

Frederick C. schreef:

---

<div class="post-metadata">

**Author:** ![rudy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5fc32e/32.png) [@rudy](https://www.ruby-forum.com/u/rudy)\
**Post date:** [November 18, 2006, 9:35pm UTC](https://www.ruby-forum.com/t/one-record-too-many-stored-with-null-why/76417/5 "2006-11-18T21:35:27Z")

</div>

Hi Fred, thanks for replying. Unjfortunately, I don’t think that is the  
case. The rubrics all come from a predefined list, so there is no  
saving involved before @rubrics is created. That is what makes is so  
wierd for me.

Frederick C. schreef:
