Note that there are some explanatory texts on larger screens.

plurals
  1. PORails activerecord possible delay with big tables
    primarykey
    data
    text
    <p>I have Message model which have like a tons of fields and around 10 million entries in the table.</p> <p>Now i also have an SomeItem model which looks like this(it have just 1000 entries):</p> <pre><code>class SomeItem &lt; ActiveRecord::Base belongs_to :item, :polymorphic =&gt; true # "Message" is one of the item types end </code></pre> <p>now in have these two consecutive lines of code which bother me:</p> <pre><code>m = Message.new(:fild_one =&gt; 1, ...) m.save s = SomeItem.create(:item =&gt; m) </code></pre> <p>Now if see <code>m</code> is getting saved in the database fine at: <code>Sat, 05 Oct 2013 15:01:06 UTC +00:00</code> and <code>s</code> at <code>Sat, 05 Oct 2013 15:01:23 UTC +00:00</code> and thats fine.</p> <p>but when i do: <code>s.item_type it gives me "Message"</code> which is fine , but <code>s.id it gives me nil</code> in 3 out of of 1000 entries.</p> <p>So my question is: Is there an kind of delay that prevents <code>m</code> created in the previous line to be used in the <code>s</code> created in the next line.</p> <p>NOTE: 1) Message table is huge containing millions of entries</p> <p>2) SomeItem table is small containing just 1000 of entries</p> <p>3) As per me understanding rails execute these two sentences sequentially , but that does not explain this behavior.</p> <p>Anyone noticed this before and if yes and if its a known thing what can be done to prevent this?</p> <p>Thanks in advance. I understand the question looks silly , but its a real life scenario and is happening on my live project.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload