adelevie / ParseModel

An Active Record pattern for your Parse models on RubyMotion.
MIT License
153 stars 15 forks source link

Thread Safe Issue?? #19

Open TheBerg opened 11 years ago

TheBerg commented 11 years ago
(main)> 2013-07-06 20:50:33.741 reward-center[57322:c07] query.rb:29:in `block in getFirst': undefined method `new' for nil:NilClass (NoMethodError)

I wasn't getting this issue in an older (1.2 I think) version of RubyMotion, but in the latest version of Ruby Motion I am now getting this error on this code:

class Section
  include ParseModel::Model

  field :name
  field :user

  attr_reader :goals

  def loadGoals
    @goals = []
    query = Goal.query
    query.whereKey("section", equalTo: self.PFObject)
    query.find do |goals, error|
      @goals = goals
    end
  end

  def self.reloadAllFromServer
    @all = []
    query = Section.query
    query.setClassObject(Section)
    query.find do |sections, error|
      @all = sections
      sections.each { |section| section.loadGoals; }
    end
  end
end

Section.reloadAllFromServer

We load several sections and do a query to get all of the queries for each section (max 5 sections).

Thoughts?

TheBerg commented 11 years ago

Somehow @classObject is being nullified....weird!!

TheBerg commented 11 years ago

So I put some logging in:

[Find]   #<ParseModel::ParseQuery:0xbee46a0> #<NSThread:0x9d58740> @classObject: Section
[Block]  #<ParseModel::ParseQuery:0xbee46a0> #<NSThread:0x9d58740> @classObject:

Same object, Same thread, but the @classObject is null.