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

has_one nested form always required? #1581

Closed
axsuul opened this issue Mar 27, 2013 · 6 comments
Closed

has_one nested form always required? #1581

axsuul opened this issue Mar 27, 2013 · 6 comments

Comments

@axsuul
Copy link

axsuul commented Mar 27, 2013

I followed instructions for doing a has_one association and using the nested form approach @ https://github.com/sferik/rails_admin/wiki/Has-one-association. The nested form shows up fine in the parent model, however, the parent record doesn't save because the has_one nested form is always required to be filed out now. How do I make the has_one form optional?

@drale2k
Copy link

drale2k commented Apr 14, 2013

I have the same issue. My polymorphic "video_assets" model shows as "optional" but i can't save the parent because validation fails on "video_asset", saying it can't be blank although it is not required by any validation.

@baldursson
Copy link

I also have a similar issue. I have a has_one relation, which is optional. Since there is no validation on the related model, rails_admin creates a blank record when saving the parent model. Very irritating.

The user should have to manually create the associated model as it works with has_many associations. If the has_one relation is compulsory, there would be no meaning in putting it in a separate model as it could just as well be attributes of the parent.

@bbenezech
Copy link
Collaborator

Reject it if one of the main field is blank. There is no way for RailsAdmin to tell if the record is significant or not.

@baldursson
Copy link

Of course not... RailsAdmin shouldn't create the related model if I don't tell it to. That was the point.

@baldursson
Copy link

I have created a fork where I have rewritten how rails_admin handles has_one associations (I haven't created any specs yet though), https://github.com/baldursson/rails_admin/tree/optional-has-one

Associated models with a has_one relation is not created by default now, it's instead up to the user to explicitly create it. I really do think this is how it should work.

@mshibuya
Copy link
Member

Fixed by #1632.

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

5 participants