Ripple associations problem

Antonio Fernández Vara antoniofernandezvara at gmail.com
Wed Nov 10 13:52:33 EST 2010


Hi all,

I hope you can help me with this problem. I'm new to ripple/riak and Im
trying a bit of code on rails. I'm trying a little application with Devise
just to see how it works.

Just trying a few things I found this problem:


-----
class User
  include Ripple::Document

  devise :database_authenticatable, :confirmable,
         :rememberable, :registerable, :trackable, :timeoutable,
:validatable,
         :token_authenticatable

  property :email,                 String, :presence => true
  property :password,              String
  property :password_confirmation, String

  timestamps!

  key_on :email

  one :profile

  def id
    email
  end

end


class Profile
  include Ripple::Document

  property :first_name,        String
  property :last_name,         String

  property :username,          String,    :presence => true

  timestamps!

  key_on :username

  one :user

  def id
    username
  end

end



----
*In the console.*

 >>     u = User.create(:email => 'antoniofernandezvara at gmail.com',
:password => '123456', :password_confirmation => '123456')
=> <User:antoniofernandezvara at gmail.com<User%3Aantoniofernandezvara at gmail.com>encrypted_password="$2a$10$cQVKORpRIf3TGi2Z8SBXFOy6bEsnLAdbtNRTLLn4t0yKq1X37jsd2"
created_at=Wed Nov 10 18:40:43 UTC 2010 updated_at=Wed Nov 10 18:40:43 UTC
2010 confirmation_sent_at=Wed Nov 10 18:40:43 UTC 2010
password_confirmation=nil last_sign_in_ip=nil last_sign_in_at=nil
sign_in_count=nil password_salt="$2a$10$cQVKORpRIf3TGi2Z8SBXFO"
current_sign_in_ip=nil authentication_token=nil remember_token=nil
current_sign_in_at=nil confirmation_token="GsVcI_YJKir5lB8nljG5"
remember_created_at=nil password=nil email="antoniofernandezvara at gmail.com"
confirmed_at=nil>
>>     p = Profile.create(:username => 'fernandezvara', :first_name =>
'Antonio', :last_name => 'Fernndez Vara')
=> <Profile:fernandezvara created_at=Wed Nov 10 18:41:02 UTC 2010
updated_at=Wed Nov 10 18:41:02 UTC 2010 username="fernandezvara"
last_name="Fernndez Vara" first_name="Antonio">
>> u.profile = p
=> <Profile:fernandezvara created_at=Wed Nov 10 18:41:02 UTC 2010
updated_at=Wed Nov 10 18:41:02 UTC 2010 username="fernandezvara"
last_name="Fernndez Vara" first_name="Antonio">
>> u.save
=> true
>> p.user = u
=> <User:antoniofernandezvara at gmail.com<User%3Aantoniofernandezvara at gmail.com>encrypted_password="$2a$10$cQVKORpRIf3TGi2Z8SBXFOy6bEsnLAdbtNRTLLn4t0yKq1X37jsd2"
created_at=Wed Nov 10 18:40:43 UTC 2010 updated_at=Wed Nov 10 18:41:14 UTC
2010 confirmation_sent_at=Wed Nov 10 18:40:43 UTC 2010
password_confirmation=nil last_sign_in_ip=nil last_sign_in_at=nil
sign_in_count=nil password_salt="$2a$10$cQVKORpRIf3TGi2Z8SBXFO"
current_sign_in_ip=nil authentication_token=nil remember_token=nil
current_sign_in_at=nil confirmation_token="GsVcI_YJKir5lB8nljG5"
remember_created_at=nil password=nil email="antoniofernandezvara at gmail.com"
confirmed_at=nil>
>> p.save
=> true


*--- Creation and associations work correctly. (at least it appears)*
*
*
*---------- First, query for the profile of the user (Works!)*

?> uu = User.find('antoniofernandezvara at gmail.com')
=> <User:antoniofernandezvara at gmail.com<User%3Aantoniofernandezvara at gmail.com>encrypted_password="$2a$10$cQVKORpRIf3TGi2Z8SBXFOy6bEsnLAdbtNRTLLn4t0yKq1X37jsd2"
created_at=Wed Nov 10 18:40:43 UTC 2010 updated_at=Wed Nov 10 18:41:14 UTC
2010 confirmation_sent_at="Wed, 10 Nov 2010 18:40:43 -0000"
password_confirmation=nil last_sign_in_ip=nil last_sign_in_at=nil
sign_in_count=nil password_salt="$2a$10$cQVKORpRIf3TGi2Z8SBXFO"
current_sign_in_ip=nil authentication_token=nil remember_token=nil
current_sign_in_at=nil confirmation_token="GsVcI_YJKir5lB8nljG5"
remember_created_at=nil password=nil email="antoniofernandezvara at gmail.com"
confirmed_at=nil>
>> uu.profile
=> <Profile:fernandezvara created_at=Wed Nov 10 18:41:02 UTC 2010
updated_at=Wed Nov 10 18:41:26 UTC 2010 username="fernandezvara"
last_name="Fernndez Vara" first_name="Antonio">


*----------- Second, query for the user referenced by the profile (Error!)*

?> pp = Profile.find('fernandezvara')
=> <Profile:fernandezvara created_at=Wed Nov 10 18:41:02 UTC 2010
updated_at=Wed Nov 10 18:41:26 UTC 2010 username="fernandezvara"
last_name="Fernndez Vara" first_name="Antonio">
>> pp.user
NoMethodError: undefined method `key' for nil:NilClass
from
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.1/lib/active_support/whiny_nil.rb:48:in
`method_missing'
from
/Library/Ruby/Gems/1.8/gems/ripple-0.8.2/lib/ripple/document/finders.rb:121:in
`instantiate'
from
/Library/Ruby/Gems/1.8/gems/ripple-0.8.2/lib/ripple/associations/one_linked_proxy.rb:25:in
`send'
from
/Library/Ruby/Gems/1.8/gems/ripple-0.8.2/lib/ripple/associations/one_linked_proxy.rb:25:in
`find_target'
from
/Library/Ruby/Gems/1.8/gems/ripple-0.8.2/lib/ripple/associations/proxy.rb:113:in
`load_target'
from
/Library/Ruby/Gems/1.8/gems/ripple-0.8.2/lib/ripple/associations/proxy.rb:41:in
`inspect'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:302:in
`output_value'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:151:in
`eval_input'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:263:in
`signal_status'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:147:in
`eval_input'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:146:in
`eval_input'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:in
`start'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:69:in
`catch'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:69:in
`start'
from
/Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in
`start'
from
/Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in
`start'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.1/lib/rails/commands.rb:23
from script/rails:6:in `require'
from script/rails:6>>


Can someone point me what i'm doing wrong? I'm so lost.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20101110/72211891/attachment.html>


More information about the riak-users mailing list