2013-05-16 3 views
0

데이터를 저장하기 전에 데이터를 조작해야하는 몇 가지 시나리오가 있습니다.geddy로 저장하기 전에 데이터 조작

저는 CakePHP 배경을 가지고 있기 때문에 Model의 beforeSave 메소드에서 일반적으로 할 것입니다.

geddy에서 사용할 수있는 모델은 무엇입니까?

답변

1

Model events을 확인하십시오.

이 User.on 결과로 내 모델을 제대로 구현하고있는 경우
var MyModel = function() { ... }; 

MyModel = geddy.model.register('MyModel', MyModel); 

MyModel.on('beforeSave', function(data){ 
    console.log(data); 
}) 
+0

확실하지 않음 ('를 BeforeSave', 기능() { ^ 형식 오류 : 개체 기능 예를 들어

Both the base model 'constructors,' and model instances are EventEmitters. The emit events during the create/update/remove lifecycle of model instances. In all cases, the plain-named event is fired after the event in question, and the 'before'-prefixed event, of course happens before.

The 'constructor' for a model emits the following events:

  • beforeCreate
  • create
  • beforeValidate
  • validate
  • beforeUpdateProperties
  • updateProperties
  • beforeSave (new instances, single and bulk)
  • save (new instances, single and bulk)
  • beforeUpdate (existing single instances, bulk updates)
  • update (existing single instances, bulk updates)
  • beforeRemove remove

() { this.defineProperties ({ 이메일 : {유형 : '문자열'}, 비밀번호 : {유형 : '문자열'} }); }에는 'on'이라는 메서드가 없습니다 – timstermatic

+0

@wiseguysonly 내 대답이 업데이트되었습니다. 아이템을 저장하는 방법을 모르겠다 - beforeSave' 이벤트 내부에서'this' 또는'arguments'를 로깅하여 조작하려는 아이템이 어디에 있는지 확인하십시오. 나에게 당신의 진전에 대해 알려주세요 :) – JAM

+0

고마워요. 귀하의 대답을 편집하여 데이터 인수를 익명 함수에 추가했습니다. 이것으로 나는 데이터를 할 수 있습니다. 패스워드 등 – timstermatic

관련 문제