What is causing this ActiveRecord::ReadOnlyRecord error?

后端 未结 6 684
我寻月下人不归
我寻月下人不归 2020-12-07 08:18

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 =          


        
6条回答
  •  臣服心动
    2020-12-07 08:45

    select('*') seems to fix this in Rails 3.2:

    > Contact.select('*').joins(:slugs).where('slugs.slug' => 'the-slug').first.readonly?
    => false
    

    Just to verify, omitting select('*') does produce a readonly record:

    > Contact.joins(:slugs).where('slugs.slug' => 'the-slug').first.readonly?
    => true
    

    Can't say I understand the rationale but at least it's a quick and clean workaround.

提交回复
热议问题