# Record cannot be saved

**URL:** <https://www.ruby-forum.com/t/record-cannot-be-saved/147485>\
**Category:** Ruby\
**Created:** [September 2, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/record-cannot-be-saved/147485 "2008-09-02T12:25:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 2, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/record-cannot-be-saved/147485/1 "2008-09-02T12:25:53Z")

</div>

Hi, all!

Maybe a noob question, sorry, but I’m really stuck with this.  
I have 2 models with has\_many and belongs\_to associations.  
class Transaction \< ActiveRecord::Base  
has\_many :bonuses, :class\_name =\> ‘TransactionBonus’  
end  
class TransactionBonus \< ActiveRecord::Base  
belongs\_to :transaction  
end

The problem is that I cannot save TransactionBonus record to the  
database - it’s simply doesn’t do anything! Here is my irb console  
output with test records:

> > transaction=Transaction.find(1)  
> > =\> #\<Transaction id: 1, card\_account\_id: 1, loyalty\_id: 0,  
> > discount\_level: 1, sale\_session\_id: 5, sum: 123.0, created\_at:  
> > “2008-09-01 13:48:10”, updated\_at: “2008-09-01 13:48:10”\>
> 
> > transaction.bonuses  
> > =\> []
> 
> > bonus=transaction.bonuses.create(:transaction\_id =\> 1,:taken\_bonus =\> 123,:collected\_bonus =\> 34,:final\_sum =\> 99)  
> > =\> #\<TransactionBonus id: nil, transaction\_id: 1, taken\_bonus: 123.0,  
> > collected\_bonus: 34.0, final\_sum: 99.0, created\_at: nil, updated\_at:  
> > nil\>
> 
> > transaction.bonuses  
> > =\> [#\<TransactionBonus id: nil, transaction\_id: 1, taken\_bonus: 123.0,  
> > collected\_bonus: 34.0, final\_sum: 99.0, created\_at: nil, updated\_at:  
> > nil\>]
> 
> > bonus.save  
> > =\> #\<Transaction id: 1, card\_account\_id: 1, loyalty\_id: 0,  
> > discount\_level: 1, sale\_session\_id: 5, sum: 123.0, created\_at:  
> > “2008-09-01 13:48:10”, updated\_at: “2008-09-01 13:48:10”\>
> 
> > bonus  
> > =\> #\<TransactionBonus id: nil, transaction\_id: 1, taken\_bonus: 123.0,  
> > collected\_bonus: 34.0, final\_sum: 99.0, created\_at: nil, updated\_at:  
> > nil\>

Please, note id: nil for the bonus var, it means that the record is  
not saved to the database.  
Can you suggest why?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 2, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/record-cannot-be-saved/147485/2 "2008-09-02T12:30:36Z")

</div>

Some more information:

1. I have another models in my application, and all of them are saved  
just fine  
TransactionBonus is the only exception
2. Table structure matches exactly the model records:  
CREATE TABLE IF NOT EXISTS `transaction_bonuses` (  
`id` int(11) NOT NULL auto\_increment,  
`transaction_id` int(11) NOT NULL,  
`taken_bonus` float default NULL,  
`collected_bonus` float default NULL,  
`final_sum` float default NULL,  
`created_at` datetime default NULL,  
`updated_at` datetime default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO\_INCREMENT=1 ;

This is really mysterious for me…
