-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 to type an attribute that returns a model but doesn't use a has_one association #2546
Comments
I'm not really sure what a good suggestion for this might be, aside from writing a custom field (which, perhaps is too much in this case?). I will note #2384, though, where we've found other cases where |
A custom field is probably a good option, particularly since #2658 However, I think it's reasonable to do with a |
We tried to remove `:class_name` (along with some others), as it didn't seem like they had a legitimate use as of thoughtbot#2384 and thoughtbot#2546. But we've been seeing various cases where it's still helpful to have. Closes thoughtbot#2384.
@mpvosseller, how did you get on? Did a custom field work out here? |
@nickcharlton I just kept it as a |
My
Foo
model has a method calledbar
that returns aBar
model instance (or nil).It is technically not a
has_one
association though because there is not foreign key. Rather thebar
method uses some business logic to determine whichBar
to return.In the
Foo
dashboard, what "type" should I use for thebar
attribute?I found that I can use the "Field::HasOne" with the
class_name
option but that option is deprecated:If I omit the
class_name
option Administrate crashes because (I think) it can't determine the type via reflection.Thanks.
The text was updated successfully, but these errors were encountered: