makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Sidekiq throws 'Active Record Unknown Primary Key Error' on Active Type object #49

Closed uzomao closed 9 years ago

uzomao commented 9 years ago

[Copied from here]

I am using the Sidekiq gem in my Rails app to handle some long-running processes asynchronously. As illustrated in this Railscast, a reference to the model to be processed is passed as an argument to the perform_async method of the worker class doing the background processing.

This would not be a problem if the model in question was an Active Record object. However it is an Active Type object designed to "quack like ActiveRecord" and unfortunately it does not quack as loudly so I get an ActiveRecord::UnknownPrimaryKeyError.

How do I set a primary key for a Ruby object that really is not a db object and convince Sidekiq to treat it as such? Unable to glean information on how to do this from the Active Type Github page.

Any help will be greatly appreciated!

triskweline commented 9 years ago

Please see answer on Stackoverflow. In this case you can use some of the attributes in the Object, or all by calling #attributes.