Skip to content

Instantly share code, notes, and snippets.

@takuyan
Created August 22, 2012 14:11
Show Gist options
  • Save takuyan/3425993 to your computer and use it in GitHub Desktop.
Save takuyan/3425993 to your computer and use it in GitHub Desktop.
#
# lib/models/article.coffee
# => Resources/models/article.js
#
TiActiveRecord = require 'lib/TiActiveRecord'
class Article extends TiActiveRecord
@dbName = 'myapp'
@tableName = 'articles'
@properties =
uid: 'integer'
title: 'text'
body: 'text'
image_url: 'text'
image_name: 'text'
pv: 'integer'
#
# class method
#
@findAllByUserId = (userId) ->
sql = "SELECT * FROM #{@tableName} WHERE USER_ID = ?"
@read sql, userId
#
# instance method
#
getImageDir: ->
imageDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "article#{@uid}")
unless imageDir.exists()
imageDir.createDirectory()
imageDir
Article.init()
module.exports = Article
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment