 
 Trigger = Parse.Object.extend 'Trigger',
   create: (props, form) ->
+    trigger = @
     @setProperties props
     @save()
-      .then =>
-        @addToForm(form)
       .then ->
-        @id
+        trigger.addToForm(form)
+      .then ->
+        trigger
 
   setProperties: (props) ->
     type = props.type

    relation = form.relation 'triggers'
    relation.add @
    form.save()


Question = Parse.Object.extend 'Question',
  addToForm: (form) ->
    relation = form.relation 'questions'
    relation.add @
    form.save()

module.exports =
  Survey: Survey

    form = @
    @getLastQuestionOrder()
      .then (lastQuestionOrder) ->
        question = new Question()
        question.create(props, lastQuestionOrder, form)
      .then (question) ->
        question

  addTrigger: (props) ->
    trigger = new Trigger()
    trigger.create(props, @)
      .then (trigger) ->
        trigger

  getTrigger: ->
    query = @relation('triggers').query()
