Forum: Ruby on Rails Read Only Error Since 1.1?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 HH (Guest)
on 2006-04-03 21:46
(Received via mailing list)
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
E82f7380b9a55883e7674e95a0d19aa5?d=identicon&s=25 Dallas (Guest)
on 2006-05-15 19:52
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
E82f7380b9a55883e7674e95a0d19aa5?d=identicon&s=25 Dallas (Guest)
on 2006-05-16 15:37
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



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
Ff82af3238a57fbd1212832ec1a19f28?d=identicon&s=25 Dylan Stamat (Guest)
on 2006-06-30 07:36
(Received via mailing list)
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 :)
This topic is locked and can not be replied to.