I can't find that this behavior is documented anywhere and it feels like
it's a bug:
Scenario #1 (expected behavior):
[89] pry(main)> user = *User*.with_pk *358*
=> #<DonorSee::User @values={:id=>358, :first_name=>"asdasd",
:last_name=>"sadasd", :email=>"[email protected]",
:password_hash=>"$2a$10$qBwNaRsYguLvhNlLlj7W3ulKWoaSOHptTgejvLKDn/OuOU6hZpjRq",
:fb_id=>nil, :created_at=>2017-03-20 03:45:45 -0700,
:updated_at=>2018-11-06 15:27:41 -0700,
:stripe_customer_id=>"cus_AJvKRYSgUr9Odu", :photo_url=>nil,
:app_version=>nil, :bio=>nil, :stripe_plan_id=>nil,
:video_promises_kept_cache=>0, :video_promises_broken_cache=>0,
:anonymous=>false, :prompt_to_subscribe=>true, :num_projects_cache=>0,
:num_partially_funded_projects_cache=>0, :num_funded_projects_cache=>0,
:num_funded_projects_with_video_cache=>0, :num_givers_cache=>0,
:last_gift_card_unlocked_at=>2018-11-06 15:27:38 -0700}>
[90] pry(main)> *GiftCardPromoOption*.where(user: user).first
=> #<DonorSee::GiftCardPromoOption @values={:id=>8, :user_id=>358,
:gift_card_id=>15, :created_at=>2018-11-06 15:26:00 -0700,
:updated_at=>nil}>
[91] pry(main)> *GiftCardPromoOption*.where(user: user).where{created_at >=
user.last_gift_card_unlocked_at}.first
=> *nil*
Scenario #2 (unexpected behavior):
[92] pry(main)> @user = *User*.with_pk *358*
=> #<DonorSee::User @values={:id=>358, :first_name=>"asdasd",
:last_name=>"sadasd", :email=>"[email protected]",
:password_hash=>"$2a$10$qBwNaRsYguLvhNlLlj7W3ulKWoaSOHptTgejvLKDn/OuOU6hZpjRq",
:fb_id=>nil, :created_at=>2017-03-20 03:45:45 -0700,
:updated_at=>2018-11-06 15:27:41 -0700,
:stripe_customer_id=>"cus_AJvKRYSgUr9Odu", :photo_url=>nil,
:app_version=>nil, :bio=>nil, :stripe_plan_id=>nil,
:video_promises_kept_cache=>0, :video_promises_broken_cache=>0,
:anonymous=>false, :prompt_to_subscribe=>true, :num_projects_cache=>0,
:num_partially_funded_projects_cache=>0, :num_funded_projects_cache=>0,
:num_funded_projects_with_video_cache=>0, :num_givers_cache=>0,
:last_gift_card_unlocked_at=>2018-11-06 15:27:38 -0700}>
[93] pry(main)> *GiftCardPromoOption*.where(user: @user).first
=> #<DonorSee::GiftCardPromoOption @values={:id=>8, :user_id=>358,
:gift_card_id=>15, :created_at=>2018-11-06 15:26:00 -0700,
:updated_at=>nil}>
[94] pry(main)> *GiftCardPromoOption*.where(user: @user).where{created_at
>= @user.last_gift_card_unlocked_at}.first
NoMethodError: undefined method `last_gift_card_unlocked_at' for
nil:NilClass
from (pry):53:in `block in <main>'
---------------------
I've been able to recreate the above behavior with a number of different
data models. If I use a local variable to store a reference to a Class
instance, then de-reference that local variable in a where{} clause, it
works fine. But if I use an instance variable to store a reference to a
Class instance, then de-reference that instance variable in a where{}
clause, it fails with "undefined method... for nil:NilClass"
Thanks,
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.