financing应用的model

本文介绍如何使用 Ruby on Rails 迁移文件创建用户、物品及记录三个模型,并定义了它们之间的关联关系。用户模型包含姓名和密码字段;物品模型包含内容和类型字段,并与用户和其他物品关联;记录模型则包含详细内容、金额、日期等信息,同时关联到物品和用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值