Record cannot be saved

R

rasfast

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 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>=> [#<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 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">=> #<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?
 
R

rasfast

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top