# Odd behavior on update

**URL:** <https://www.ruby-forum.com/t/odd-behavior-on-update/74832>\
**Category:** Rails\
**Created:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/odd-behavior-on-update/74832 "2006-11-07T10:58:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/odd-behavior-on-update/74832/1 "2006-11-07T10:58:32Z")

</div>

If I have the following two legacy data tables:

CREATE TABLE `statusactivities` (  
`id` int(11) NOT NULL auto\_increment,  
`activity` int(11) NOT NULL default ‘0’  
)

CREATE TABLE `activities` (  
`id` int(11) NOT NULL auto\_increment,  
`activity` varchar(60) NOT NULL default ‘’  
)

And thus, the two models:

class Statusactivity \< ActiveRecord::Base  
set\_table\_name ‘statusactivities’  
belongs\_to :activity, :foreign\_key =\> ‘activity’  
end

class Activity \< ActiveRecord::Base  
set\_table\_name ‘activities’  
has\_many :statusactivities, :foreign\_key =\> ‘activity’  
end

and I go to update a Statusactivity, I get the following exception.  
Please note at the bottom, the parameters – it doesn;t appear to  
be anything wrong here to me. Can someone please enlighten me as  
to what I may have specified wrong here that I am unable to update  
a record here? (I am using scaffolding\_extensions btw) - Ralph V.

ActiveRecord::AssociationTypeMismatch in  
CrudController#update\_statusactivity

Activity expected, got String

C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/associations/association\_proxy.rb:134:in  
`raise_on_type_mismatch' C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/belongs_to_association.rb:22:in`replace’  
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active\_record/associations.rb:850:in  
`activity=' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:344:in`send’  
#{RAILS\_ROOT}/vendor/plugins/scaffolding\_extensions/lib/scaffolding\_extensions.rb:344:in  
`update_scaffold_attributes' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:343:in`each’  
#{RAILS\_ROOT}/vendor/plugins/scaffolding\_extensions/lib/scaffolding\_extensions.rb:343:in  
`update_scaffold_attributes' #{RAILS_ROOT}/vendor/plugins/scaffolding_extensions/lib/scaffolding_extensions.rb:985:in`update\_statusactivity’  
C:/INSTAN~2/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action\_controller/base.rb:941:in  
`send’

Request

Parameters: {“commit”=\>“Update statusactivity”, “id”=\>“1”,  
“statusactivity”=\>{“activity”=\>“1”}}

---

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/odd-behavior-on-update/74832/2 "2006-11-07T10:58:42Z")

</div>

> and I go to update a Statusactivity, I get the following exception.

The problem is when you are doing the above activity, can you post the  
code?

thanks,  
andy

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/odd-behavior-on-update/74832/3 "2006-11-07T10:58:48Z")

</div>

There isn;t any other than the model descriptions above – the rest is  
handled by scaffolding\_extensions plugin. -Ralph

---

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [November 7, 2006, 10:59am UTC](https://www.ruby-forum.com/t/odd-behavior-on-update/74832/4 "2006-11-07T10:59:18Z")

</div>

On 11/3/06, Ike [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There isn;t any other than the model descriptions above – the rest is  
> handled by scaffolding\_extensions plugin. -Ralph

You can’t have your belongs\_to association have the same name as your  
foreign key. Change the foreign key to activity\_id or rename the  
belongs\_to association.

Jeremy
