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

Cannot selectively update attributes on a model #1

Open
sachinsiby opened this issue Sep 29, 2015 · 3 comments
Open

Cannot selectively update attributes on a model #1

sachinsiby opened this issue Sep 29, 2015 · 3 comments

Comments

@sachinsiby
Copy link
Contributor

Because Inform defaults the attributes to nil, we are unable to selectively update attributes. i.e. you must pass in all of the attributes on the model.

e.g.

class PersonForm
  include Inflorm
  attribute :name 
  attribute :age
  attribute :gender
end

PersonForm.new(age: 27).to_h #=> {name: nil, age: 27, gender: nil}

So when you do a Person#update_attributes in your #persist! method, it overwrites the existing name and gender attributes to null. This is problematic, especially if you have non-null constraints on your database.

@bradrobertson
Copy link
Contributor

What's the use-case? I don't think inflorm is really required if you're just updating one attribute.

Having said that I've been thinking about this from a patch perspective also, and I think it makes sense to be able to selectively update attributes. The only thing is that inflorm doesn't directly map to a single model. The whole point of it is to define your pubic API and validations completely separately from the models, so I'm wondering how you'd actually do this.

Is this a blocker?

@sachinsiby
Copy link
Contributor Author

The use case is for when you have a <form> that does not include fields for all of the attributes.

Maybe the solution for this is to have a separate Inflorm class for this slimmed-down form? Though this seems a little like it'd be extra overhead…

@bradrobertson
Copy link
Contributor

Ya I know the general use case, I was wondering if there's something specific in our app requiring it. For now I'd suggest ya that we have specific endpoints for one-off modifications (ie 'publish/unpublish') that could use slimmed down forms

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

2 participants