Skip to content
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

Configure for use without ActiveRecord? #51

Closed
realityendshere opened this issue Dec 17, 2014 · 7 comments
Closed

Configure for use without ActiveRecord? #51

realityendshere opened this issue Dec 17, 2014 · 7 comments

Comments

@realityendshere
Copy link

In experimenting with this gem, I seem to run into trouble trying to use this with a NoSQL-style database instead of ActiveRecord. When trying to create new records with POST, I encounter the error:

uninitialized constant JSONAPI::ActiveRecordOperationsProcessor::ActiveRecord

Can the gem be configured to use alternative data storage strategies?

Thanks.

@lgebhardt
Copy link
Member

@realityendshere, I'm sorry you are having trouble with a NoSQL data source. I haven't done much testing with non ActiveRecord data sources. I think the problem is that the ResourceController requires the ActiveRecordOperationsProcessor by default. I probably need to make a few changes so that isn't loaded if you are not using ActiveRecord.

I think the major change we need is to set an option for the OperationsProcessor in the configuration. Then have ResourceController.create_operations_processor use this to load the appropriate OperationsProcessor. I'll see if I can get to that soon, or you are welcome to try and fix it yourself if you want.

@realityendshere
Copy link
Author

As a temporary workaround, I use the "plain" OperationsProcessor instead of the one for ActiveRecord:

#config/initializers/jsonapi_resouces.rb
require 'jsonapi/resource_controller'

module JSONAPI
  class ResourceController

    def create_operations_processor
      JSONAPI::OperationsProcessor.new
    end

  end
end

I haven't gotten too deep into if or how well this works with associations or really anything beyond rudimentary CRUD operations on a couple of records. But having a running Rails app is a start.

@bvandenbos
Copy link

Even with the workaround, you get this error when validations fail.

JSONAPI::Resource has ActiveRecord-based rescues in it:

    def _save
      @model.save!
      @save_needed = false
    rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
      raise JSONAPI::Exceptions::ValidationErrors.new(e.record.errors.messages)
    end

https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/resource.rb#L118

@realityendshere
Copy link
Author

@bvandenbos This is true! See issue #127.

@bvandenbos
Copy link

Ah - didn't see that issue covered it already. Thanks!

@acorncom
Copy link
Contributor

Was this handled by #192 ?

@realityendshere
Copy link
Author

The projects I've worked on in the last year have all used ActiveRecord. I hesitate to confirm the fix.

But: I will close this issue. If there are still challenges using alternatives to ActiveRecord, please feel free to comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants