Search code examples
rubymotion

Outputting data with NanoStoreInMotion


I have successfully been able to create a user using NanoStoreInMotion. I can query on it and see the object. What I am having an issue with is outputting data. For example:

User model:

class User < NanoStore::Model
  :first_name => "Jason"
  :last_name => "Beam"

  user = User.find(:first_name => "Jason")
  #This returns the object [#<User:0xab96ab0>]
end

With ruby, normally to call on a specific field I would just do user.first_name. This throws an error, "undefined method 'first_name' for [#]:Array (NoMethodError)


Solution

  • If I remember correctly find returns an Array so you need to do something like user[0].first_name

    Based on my experience I would advise against NanoStoreInMotion. I wouldn't exclude my own inability to use it correctly, but for me it was unreasonably slow (storing thousands of relatively complex objects) and throwing a lot of cryptic errors.

    So I moved to MotionModel and I am very happy with it.