title: Using sequelize to store and retrieve JSON objects within a Model/Instance
body: <p>I'm looking to leverage sequelize on a big project, and was hoping I could use it to store a JSON Object as a property in a Model.</p>
  
  <p>I feel like I'm struggling with this, but perhaps I'm missing something simple?</p>
  
  <p>I'm defining a model (<code>Context</code>) as follows:</p>
  
  <pre><code>var contextProperties = {
  
    contextName: { type: Sequelize.STRING, validate: { is: ["[a-z]",'i'], notEmpty: true } },
  
    _trackList: {type: Sequelize.TEXT},    
    trackList: {type: Sequelize.TEXT}
  
  }
  
  var contextGetSet = {
  
    getterMethods: {
      trackList: function(){
        return JSON.parse(this._trackList);
      }
    },
  
    setterMethods: {
      trackList: function(v){
        this._trackList = JSON.stringify(v);
      }
    }
  
  };
  
  var Context = sequelize.define('Context', contextProperties, contextGetSet);
  </code></pre>
  
  <p>Now when I create my <code>Context</code>, it seems to work before I save.</p>
  
  <pre><code>var contextMain;
  
  Context.create({contextName: "Whatever"}).success(function (context){
  
    contextMain = context;
  
    contextMain.trackList = { atrackList: "1111", anotherTrackList: 2872 };
    console.log(constextMain.trackList);
    //logs { atrackList: "1111", anotherTrackList: 2872 } as expected
  
  
    contextMain.save().success(function (contextSaved){
      console.log(contextSaved.values);
      //all values are null except for the contextName
    });
  
  });
  </code></pre>
  
  <p>So the JSON IS setting right, but the object returned by the <code>save().success()</code> method does not seem to have the proper values of what I set it to.</p>
  
  <p>When I log the object returned by the <code>save().success()</code> method (ie. <code>contextSaved.values</code>) the object looks like this:</p>
  
  <pre><code>{ contextName: 'Whatever',
    _trackList: 'null',
    trackList: null,
    id: 6,
    createdAt: Fri Dec 06 2013 15:57:39 GMT-0500 (EST),
    updatedAt: Fri Dec 06 2013 15:57:39 GMT-0500 (EST)
  }
  </code></pre>
  
  <p>Everything is null!!</p>
  
  <p>Even more weird is that when I look at the save SQL query made to save <code>contextMain</code>, it seems to be saving right!</p>
  
  <pre><code>Executing: UPDATE "Contexts" SET "contextName"='Whatever', "_trackList"='{"atrackList":"1111","anotherTrackList":2872}', "trackList"=NULL,"id"=7, "createdAt"='2013-12-06 20:59:39.278 +00:00', "updatedAt"='2013
  -12-06 20:59:39.294 +00:00' WHERE "id"=7 RETURNING *
  </code></pre>
  
  <p>Notice that: <code>"_trackList"='{"atrackList":"1111","anotherTrackList":2872}'</code></p>
  
  <p>Also when I look at the actual SQL row for it, <strong>it does have the stringified JSON object in there</strong>!</p>
  
  <p>If I load the Context using sequelize though...</p>
  
  <pre><code>Context.findAll().success(function(contexts) {
    console.log(JSON.stringify(contexts))
    // also displays null for _trackList and trackList
  });
  </code></pre>
  
  <p>So very strange. Any help greatly greatly appreciated!!
  Thanks so much! Sorry this post is so long!</p>