# Read Only Error Since 1.1?

**URL:** <https://www.ruby-forum.com/t/read-only-error-since-1-1/93476>\
**Category:** Rails\
**Created:** [April 3, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/read-only-error-since-1-1/93476 "2006-04-03T21:46:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [April 3, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/read-only-error-since-1-1/93476/1 "2006-04-03T21:46:02Z")

</div>

Since I upgraded to 1.1, I am getting ‘ActiveRecord::ReadOnlyRecord’  
exceptions when trying to save a specific record.

I read up on ActiveRecord::Base.readonly? but I don’t think the  
condition  
there (objects pulled in from a certain JOIN type) applies.

Here’s my code that is throwing the exception:

@company = session[:company]  
@company.bytes\_used = @company.calculate\_megabytes\_used  
@company.save  
session[:company] = @company

This was working under 1.0 and I checked SVN and I don’t see any changes  
to  
this code in my repository since then…

What could be causing this? Any ideas?

Thanks,  
Hunter

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [May 15, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/read-only-error-since-1-1/93476/2 "2006-05-15T19:52:20Z")

</div>

I’m having the same troubles. I have a has\_and\_belongs\_to\_many  
relationship which is causing me the same problem. I modify the model  
from the association and it errors out when I save. This also worked  
for me pre 1.1. Any ideas on how I can make this work and not be read  
only? This only seems to be a problem with has\_and\_belongs\_to\_many  
realtionships.

(three tables, crawlers, teams, crawlers\_teams)  
crawler model relationship  
has\_and\_belongs\_to\_many :teams

for team in crawler.teams  
team.name = “Mets”  
team.save  
end

Thanks,  
Dallas

HH wrote:

> Since I upgraded to 1.1, I am getting ‘ActiveRecord::ReadOnlyRecord’  
> exceptions when trying to save a specific record.
> 
> I read up on ActiveRecord::Base.readonly? but I don’t think the  
> condition  
> there (objects pulled in from a certain JOIN type) applies.
> 
> Here’s my code that is throwing the exception:
> 
> @company = session[:company]  
> @company.bytes\_used = @company.calculate\_megabytes\_used  
> @company.save  
> session[:company] = @company
> 
> This was working under 1.0 and I checked SVN and I don’t see any changes  
> to  
> this code in my repository since then…
> 
> What could be causing this? Any ideas?
> 
> Thanks,  
> Hunter

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [May 16, 2006, 3:37pm UTC](https://www.ruby-forum.com/t/read-only-error-since-1-1/93476/3 "2006-05-16T15:37:13Z")

</div>

To answer my own question (and the guy before me).

Apparently you can’t use the has\_and\_belongs\_to\_many associations if you  
want to update the model from the association because its made read only  
based off this changelist. Instead it says to do a find by sql.

[http://dev.rubyonrails.org/changeset/2594](http://dev.rubyonrails.org/changeset/2594)

Dallas wrote:

> I’m having the same troubles. I have a has\_and\_belongs\_to\_many  
> relationship which is causing me the same problem. I modify the model  
> from the association and it errors out when I save. This also worked  
> for me pre 1.1. Any ideas on how I can make this work and not be read  
> only? This only seems to be a problem with has\_and\_belongs\_to\_many  
> realtionships.
> 
> (three tables, crawlers, teams, crawlers\_teams)  
> crawler model relationship  
> has\_and\_belongs\_to\_many :teams
> 
> for team in crawler.teams  
> team.name = “Mets”  
> team.save  
> end
> 
> Thanks,  
> Dallas
> 
> HH wrote:
> 
> > Since I upgraded to 1.1, I am getting ‘ActiveRecord::ReadOnlyRecord’  
> > exceptions when trying to save a specific record.
> > 
> > I read up on ActiveRecord::Base.readonly? but I don’t think the  
> > condition  
> > there (objects pulled in from a certain JOIN type) applies.
> > 
> > Here’s my code that is throwing the exception:
> > 
> > @company = session[:company]  
> > @company.bytes\_used = @company.calculate\_megabytes\_used  
> > @company.save  
> > session[:company] = @company
> > 
> > This was working under 1.0 and I checked SVN and I don’t see any changes  
> > to  
> > this code in my repository since then…
> > 
> > What could be causing this? Any ideas?
> > 
> > Thanks,  
> > Hunter

---

<div class="post-metadata">

**Author:** ![HHHHHH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@HHHHHH](https://www.ruby-forum.com/u/HHHHHH)\
**Post date:** [June 30, 2006, 7:36am UTC](https://www.ruby-forum.com/t/read-only-error-since-1-1/93476/4 "2006-06-30T07:36:02Z")

</div>

I’ve been using Join Models myself, but wanted to use an “acts\_as\_list”  
with  
a many-to-many relationship.  
Setting up something like this doesn’t currently work with a Join Model  
approach.

Someone wrote a “acts\_as\_habtm\_list” plugin that works great… but does  
requires a non-Join Model approach.

If anyone has time to whip up a Join Model version of this, that would  
be  
great 🙂
