package org.adaptlab.chpir.android.survey.Models;

import java.util.List;

import org.adaptlab.chpir.android.activerecordcloudsync.ReceiveTable;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Select;

@Table(name = "Instruments")
public class Instrument extends Model implements ReceiveTable {
    private static final String TAG = "Instrument";

    @Column(name = "Title")
    private String mTitle;

    public Instrument() {
        super();
    }

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        mTitle = title;
    }

    public List<Question> questions() {
        return getMany(Question.class, "Instrument");
    }

    public static List<Instrument> getAll() {
        return new Select().from(Instrument.class).orderBy("Id ASC").execute();
    }

    @Override
    public String toString() {
        return mTitle;
    }

    @Override
    public void createObjectFromJSON(JSONObject jsonObject) {
        try {
            setTitle(jsonObject.getString("title"));
            this.save();
        } catch (JSONException je) {
            Log.e(TAG, "Error parsing object json", je);
        }
    }
}

@@ -583,16 +583,197 @@
  mTitle;
+%0A    // https://github.com/pardom/ActiveAndroid/issues/22%0A    @Column(name = %22RemoteId%22, unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)%0A    private Long mRemoteId;
 %0A%0A    pu
@@ -939,32 +939,175 @@
 e = title;%0A    %7D
+%0A    %0A    public Long getRemoteId() %7B%0A        return mRemoteId;%0A    %7D%0A    %0A    public void setRemoteId(Long id) %7B%0A        mRemoteId = id;%0A    %7D
 %0A%0A    public Lis
@@ -1491,16 +1491,67 @@
   try %7B%0A
+            setRemoteId(jsonObject.getLong(%22id%22));%0A
         
@@ -1714,16 +1714,16 @@
 %22, je);%0A
-
         
@@ -1719,21 +1719,23 @@
 );%0A        %7D
+  
 %0A    %7D%0A%7D%0A

Replace column on remote update