-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does klass work for dynamoid? #469
Comments
Could you describe in more details the use case and what class you need to get? |
Thanks for your reply, I'm looking to use a token for my devise authentication on rails, We use dynamoid ORM on the API, so I tried using the Tiddle gem which supports multiple devices per user with it. It turned out that it doesn't have support for dynamoid, as it showed "Cannot determine authentication token class, unsupported ORM/ODM?" So I tried to trace to the error, it was here https://github.com/adamniedzielski/tiddle/blob/master/lib/tiddle/token_issuer.rb#L55 I tried getting the association class for Dynamoid from rails console, it doesn't work if resource.respond_to?(:associations) # this returns true/false for Dynamoid, It returned true in rails console Here is what my model looks like class User devise :database_authenticatable, has_many :authentication_tokens end class AuthenticationToken
end Here is an example of an active_record implementation. https://apidock.com/rails/ActiveRecord/Reflection/AssociationReflection/klass class Author < ActiveRecord::Base Author.reflect_on_association(:books).klass => Book # it's expected to return the target association's classHow can I achieve this in dynamoid? Here is a fork of the gem with my adaptations for dynamoid. |
There is no public interface to get associated model class but such logic is implemented here: def target_class
options[:class] || target_class_name.constantize
end You can find examples of usage in specs: it 'determins target class correctly' do
expect(magazine.subscriptions.send(:target_class)).to eq Subscription
expect(user.books.send(:target_class)).to eq Magazine
end To use this private method you need to have an instance of Dynamoid::Associations.const_get(type.to_s.camelcase).new(nil, name, options) |
Please I'm trying to integrate dynamoid into this gem, https://github.com/adamniedzielski/tiddle
But it's giving errors.
How can I get the class of the association?
elsif resource.respond_to?(:associations) # Dynamoid
resource.associations[:authentication_tokens]
else
def authentication_token_class(resource)
if resource.respond_to?(:association) # ActiveRecord
resource.association(:authentication_tokens).klass
elsif resource.respond_to?(:relations) # Mongoid
resource.relations['authentication_tokens'].klass
elsif resource.respond_to?(:associations) # Dynamoid
resource.associations[:authentication_tokens]
else
raise 'Cannot determine authentication token class, unsupported ORM/ODM?'
end
end
Thanks
The text was updated successfully, but these errors were encountered: