I'm trying to use cequel-devise with... Devise ^^
I have a User model:
# -*- encoding : utf-8 -*-
class User
include Cequel::Record
devise :database_authenticatable, :registerable
key :email, :varchar
column :username, :varchar
column :encrypted_password, :varchar
timestamps
end
Partitioning with the email seemed to me the best way to integrate with Devise, which will be able to efficiently look for a user by email.
Signing up goes well, but when I try to log in, I end up with the following error:
NoMethodError: undefined method `first' for #<User email: "username@email.com">
The error is located here: orm_adapter-cequel (1.0.1) lib/cequel/record/orm_adapter.rb:61:in 'find_first'.
From what I've gathered, find_first tries to build a scope using the given options to query the DB and to get the first record by calling first on that scope.
scope is assigned the following values:
scope = klass.all #=> User
scope = apply_secondary_index_scope(scope, conditions) || apply_primary_key_scope(scope, conditions) #=> User['username@email.com'] => #<User:0x007f8bc4d0e6c8>
conditions only contains an email key with value username@email.com. In the second step, this resolves to applying this key as a "primary key scope", which ends up restricting the scope to a single User instance.
I guess it's because of this behavior of #[] (from cequel/cequel:lib/cequel/record/record_set.rb):
# If {#[]} is used successively to specify all of the columns of a primary
# key, the result will be a single {Record} or a {LazyRecordCollection},
# depending on whether multiple values were specified for one of the key
# columns. In either case, the record instances will be unloaded.
Because of my relational-like table, where a partition key (email) always maps to a single User instance, #[] will always return a single Record instance.
I guess find_first should call first on the returned scope only if scope is an instance of RecordSet?
I'm trying to use
cequel-devisewith... Devise ^^I have a User model:
Partitioning with the email seemed to me the best way to integrate with Devise, which will be able to efficiently look for a user by email.
Signing up goes well, but when I try to log in, I end up with the following error:
The error is located here:
orm_adapter-cequel (1.0.1) lib/cequel/record/orm_adapter.rb:61:in 'find_first'.From what I've gathered,
find_firsttries to build a scope using the given options to query the DB and to get the first record by callingfirston that scope.scopeis assigned the following values:scope = klass.all #=> Userscope = apply_secondary_index_scope(scope, conditions) || apply_primary_key_scope(scope, conditions) #=> User['username@email.com'] => #<User:0x007f8bc4d0e6c8>conditionsonly contains anemailkey with valueusername@email.com. In the second step, this resolves to applying this key as a "primary key scope", which ends up restricting the scope to a singleUserinstance.I guess it's because of this behavior of
#[](fromcequel/cequel:lib/cequel/record/record_set.rb):Because of my relational-like table, where a partition key (email) always maps to a single User instance,
#[]will always return a singleRecordinstance.I guess
find_firstshould callfirston the returned scope only if scope is an instance ofRecordSet?