Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:27:40+00:00 2026-05-11T10:27:40+00:00

This follows this prior question, which was answered. I actually discovered I could remove

  • 0

This follows this prior question, which was answered. I actually discovered I could remove a join from that query, so now the working query is

start_cards = DeckCard.find :all, :joins => [:card], :conditions => ['deck_cards.deck_id = ? and cards.start_card = ?', @game.deck.id, true]   

This appears to work. However, when I try to move these DeckCards into another association, I get the ActiveRecord::ReadOnlyRecord error.

Here’s the code

for player in @game.players    player.tableau = Tableau.new   start_card = start_cards.pop    start_card.draw_pile = false   player.tableau.deck_cards << start_card  # the error occurs on this line end 

and the relevant Models (tableau are the players cards on the table)

class Player < ActiveRecord::Base   belongs_to :game   belongs_to :user   has_one :hand   has_one :tableau end  class Tableau < ActiveRecord::Base   belongs_to :player   has_many :deck_cards end    class DeckCard < ActiveRecord::Base   belongs_to :card   belongs_to :deck   end 

I am doing a similar action just after this code, adding DeckCards to the players hand, and that code is working fine. I wondered if I needed belongs_to :tableau in the DeckCard Model, but it works fine for the adding to player’s hand. I do have a tableau_id and hand_id columns in the DeckCard table.

I looked up ReadOnlyRecord in the rails api, and it doesn’t say much beyond the description.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:27:40+00:00Added an answer on May 11, 2026 at 10:27 am

    Rails 2.3.3 and lower

    From the ActiveRecord CHANGELOG(v1.12.0, October 16th, 2005):

    Introduce read-only records. If you call object.readonly! then it will mark the object as read-only and raise ReadOnlyRecord if you call object.save. object.readonly? reports whether the object is read-only. Passing :readonly => true to any finder method will mark returned records as read-only. The :joins option now implies :readonly, so if you use this option, saving the same record will now fail. Use find_by_sql to work around.

    Using find_by_sql is not really an alternative as it returns raw row/column data, not ActiveRecords. You have two options:

    1. Force the instance variable @readonly to false in the record (hack)
    2. Use :include => :card instead of :join => :card

    Rails 2.3.4 and above

    Most of the above no longer holds true, after September 10 2012:

    • using Record.find_by_sql is a viable option
    • :readonly => true is automatically inferred only if :joins was specified without an explicit :select nor an explicit (or finder-scope-inherited) :readonly option (see the implementation of set_readonly_option! in active_record/base.rb for Rails 2.3.4, or the implementation of to_a in active_record/relation.rb and of custom_join_sql in active_record/relation/query_methods.rb for Rails 3.0.0)
    • however, :readonly => true is always automatically inferred in has_and_belongs_to_many if the join table has more than the two foreign keys columns and :joins was specified without an explicit :select (i.e. user-supplied :readonly values are ignored — see finding_with_ambiguous_select? in active_record/associations/has_and_belongs_to_many_association.rb.)
    • in conclusion, unless dealing with a special join table and has_and_belongs_to_many, then @aaronrustad‘s answer applies just fine in Rails 2.3.4 and 3.0.0.
    • do not use :includes if you want to achieve an INNER JOIN (:includes implies a LEFT OUTER JOIN, which is less selective and less efficient than INNER JOIN.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this follows on from my last question which I thought was answered but for
This question follows on from a previous question, that has raised a further issue.
This problem follows on from a previous question . When I run the following
This question follows on from a previous question. However stackoverflow presents me from commenting
I need to build some client side code which follows this use case: An
I'm having some issues to deserialize a Json array that follows this format: [
Prior Information: (In case you are wondering where I am coming from) First Question:
Follow up question to this: Linq Combine Left Join Data Say I have the
This is a follow-up question. My prior questions: How to paste a custom format
Based upon a prior question I had Here . I wanted to join two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.