Transactions not work for array?

Hi,

I have a transaction block as follow:

begin
Hello.transaction(input1,input2)

    input1.save

    for i in 0 to count
        input2[i].input1_id = input1.id
        input2[i].save
    end
end

rescue

end

I have used validates_uniqueness_of for input2 in the model

The problem is, when there is duplicate record in input2, input1 and the
first record in input2 are inserted into db and commited.

?

Thanks.

On 10/6/06, Ianne L. [email protected] wrote:

        input2[i].save
    end
end

rescue

end

I have used validates_uniqueness_of for input2 in the model

The problem is, when there is duplicate record in input2, input1 and the
first record in input2 are inserted into db and commited.

You need to raise an exception so the transaction knows to rollback, so
use
save! (raises ActiveRecord::RecordInvalid when invalid) instead of save
(returns false when invalid).

jeremy

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs