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

Mongoid support #457

Open
redross opened this issue Dec 18, 2023 · 2 comments
Open

Mongoid support #457

redross opened this issue Dec 18, 2023 · 2 comments

Comments

@redross
Copy link

redross commented Dec 18, 2023

I've seen that sequel support was added fairly early on with #2 and was thinking if something similar could be done with mongoid. Do you see any possible issues with that? (e.g. would things like different mongo document "fields" per record break some assumptions that view templates currently have?)

For now I'll assume that following the example adapter file, a mongo adapter could be made. But this brings another question - can I use multiple adapters in the same project? E.g. I have some ActiveRecord models (in various databases) + some Mongoid documents. I only see a way on how a default_adapter could be set for all resources, but can I set it per Trestle resource?

@spohlenz
Copy link
Member

As long as the ORM layer is ActiveModel compatible (which I believe Mongoid is), then a custom adapter should be possible. I'd certainly be very happy to accept a PR with Mongoid support if you are able.

Nested objects that are sometimes found within MongoDB may be tricky to handle -- you may have success searching the issue tracker for 'nested' to see how it is handled with ActiveRecord (and accepts_nested_attributes_for), and seeing if something similar can be applied to Mongoid, but that will probably be separate from the adapter itself.

For the second part of your question, adapters can be overridden at the Resource level, e.g.

Trestle.resource(:mongoid_resource) do
  # Adapters.compose creates a new class and includes each of the modules passed to it
  self.adapter = Trestle::Adapters.compose(MongoidAdapter)
end

@saikou9
Copy link

saikou9 commented Jan 31, 2024

I tried to connect this adapter through the sequel, but nothing works for me. If anyone managed to do this, please share the connection steps

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

3 participants