Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

updateAttributes not working properly on Mongoose #35

Closed
nesterko opened this Issue · 2 comments

2 participants

@nesterko

There was an issue before about Boolean type not updating properly. In addition to that, even String type does not update consistently.

For example, we want to update one field F1. It is not updated unless in addition to F1 we make a dummy change to at least one another field (for example, F2). For some fields such trick is not necessary, for some you need it.

I am having trouble determining what is the reason behind this kind of behavior. Would be great if you could shed some light on this.

All fields are String, database is Mongoose. Thank you.

@1602
Owner
@nesterko

Alright, here are the main ingredients:

Model declaration:
Privilege = describe 'Privilege', () ->
property 'slug', String, index : true
property 'name', String
property 'activated', String, default: "no"

update inside a controller:
action 'update', ->
@privilege.updateAttributes body, (err) =>
if !err
flash 'info', 'Privilege updated'
redirect path_to.admin_privilege(@privilege)
else
flash 'error', 'Privilege can not be updated'
@title = 'Edit privilege details'
render 'edit'

_form.jade partial within views:
.clearfix
!= form.label("name")
.input
!= form.input("name")
!= form.label("slug")
.input
!= form.input("slug")
!= form.label("activated")
.input
- if (privilege.activated === "yes")
input(type="checkbox", name="activated", value="yes", checked)
- else
input(type="checkbox", name="activated", value="yes")

The only field that has trouble updating under this setup is 'activated', to update it I need to change say 'name' together with it. Changing just 'activated' does not do the trick.

This setup works fine under driver : memory.

Please let me know if you need more info.

@1602 1602 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.