---
title: "financing应用的model"
author: "hongan"
date: "2009-07-14T15:14:50Z"
tags: []
slug: "financing-model"
draft: false
lastmod: "2009-07-14T15:14:50Z"
id: 425614
url: "https://hongan.iteye.com/blog/425614"
---

```
user:
- name: string
- password: string
- has_many: [item,record]

item:
- content: string
- types: integer
- belongs_to: [user,item]
- has_many: [item,record]


record:
- content: text
- money: number
- date: date
- belongs_to: [item,user]
```

 

Ruby model:

```
class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :name
      t.string :password

      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end
```

 

```
class CreateItems < ActiveRecord::Migration
  def self.up
    create_table :items do |t|
      t.string :content
      t.integer :types
      t.references :user
      t.references :item

      t.timestamps
    end
  end

  def self.down
    drop_table :items
  end
end
```

 

```
class CreateRecords < ActiveRecord::Migration
  def self.up
    create_table :records do |t|
      t.text :content
      t.decimal :money
      t.date :date
      t.references :item
      t.references :user

      t.timestamps
    end
  end

  def self.down
    drop_table :records
  end
end
```