You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks a lot for this project. I was wondering if I'm doing something wrong here—I expect to be able to modify the properties of a model in beforeCreate, but Postgres shows the following in the database:
id | email | password | salt | created
----+---------------------+----------+------+---------
1 | test@email.com | visible? | |
Actually, the blame is beforeCreate should be right after/before beforeSave (a few lines above). In that zone, you can use the this context to change the data. I'm going to make this change.
If you want to test it you have to check the latest git version, it will take some days before pushing a new version. Or you can use the hook beforeSave which should have the same behavior for new instances (but you'll also have it trigger for not new instances).
Thanks! I've tested and it works when updating properties enumerated in the call to create, but I can't add properties—for example, to get the above to populate the salt column, I have to change the create call to include that key:
This works however rangeLength validator is checking for undefined, whereas attributes not listed in Person.create[{...}] are now initialised to null and the validation blows up.
Is it possible for an attribute to ever be undefined? Should the validation only be checking for null, or both null & undefined?
Activity
markandrus commentedon Mar 9, 2013
After looking at
/lib/Instance.js, I guess the functionality I'm looking for requires threadingdataas an argument through the hook.dresende commentedon Mar 9, 2013
Actually, the blame is
beforeCreateshould be right after/beforebeforeSave(a few lines above). In that zone, you can use thethiscontext to change the data. I'm going to make this change.Moves beforeCreate to near beforeSave so people change change instanc…
dresende commentedon Mar 9, 2013
If you want to test it you have to check the latest git version, it will take some days before pushing a new version. Or you can use the hook
beforeSavewhich should have the same behavior for new instances (but you'll also have it trigger for not new instances).markandrus commentedon Mar 9, 2013
Thanks! I've tested and it works when updating properties enumerated in the call to
create, but I can't add properties—for example, to get the above to populate the salt column, I have to change thecreatecall to include that key:Fixes bug when creating Models without all data (#69)
dresende commentedon Mar 11, 2013
Please try it now.
dxg commentedon Mar 13, 2013
This works however rangeLength validator is checking for
undefined, whereas attributes not listed inPerson.create[{...}]are now initialised tonulland the validation blows up.Is it possible for an attribute to ever be undefined? Should the validation only be checking for null, or both null & undefined?
dresende commentedon Mar 13, 2013
You're right. To be consistent, it should initialize to undefined.
Changes undefined instance properties initialization to undefined ins…
Fixes bug where beforeCreate hook is always called regardless if the …
dresende commentedon Mar 13, 2013
I'm going to assume it's fixed. If you have any other problems please reopen or create a new issue :)
markandrus commentedon Mar 14, 2013
Just tested--it works! Thanks
Merge pull request #77 from markandrus/master