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

Allow for namespaced models. #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gmhawash
Copy link

@gmhawash gmhawash commented Dec 2, 2024

Our use case allows for models to be namespaced as we're taking advantage of Rails Multi-Database access. As a result, each database models are namespaced; e.g., DB1::Tenant. We also want to be able to use the parent or scope option when we access sub-associations. e.g., DB1::Tenant.has_many :certificates, hence:

expose :tenant, model_namespace: :DB1
expose :certificate, parent: :tenant, model_namespace: :DB1

This translates to:

def tenant = DB1::Tenant.find_or_initialize_by(id: params[:id])
def certificate = tenant.certificates.find_or_initialize_by(id: params[:id])

@mattpolito
Copy link
Member

@gmhawash Thanks so much for the PR!

Before I look into this, have you tried using the model option?

It should work out like this:

expose :certificate, parent: :tenant, model: DB1::Certificate

@gmhawash
Copy link
Author

gmhawash commented Dec 4, 2024

@mattpolito the code prevents parent and model to be used at the same time.

@mattpolito
Copy link
Member

I'd like to remedy the 'incompatible option' situation over adding and additional option for name-spacing. Let me look into that.

@gmhawash
Copy link
Author

gmhawash commented Dec 4, 2024

I would be happy to try it if you do it soonish. Thanks

@mattpolito
Copy link
Member

I'm planning to take a look at it toward the end of the month around the holidays

@gmhawash
Copy link
Author

gmhawash commented Dec 5, 2024 via email

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

Successfully merging this pull request may close these issues.

2 participants