-3
A
回答
1
class Admin < ActiveRecord::Base
has_many :users
has_many :listings
end
class User < ActiveRecord::Base
belongs_to :admin
end
class Listing < ActiveRecord::Base
belongs_to :admin
end
class AddAdminUserListing < ActiveRecord::Migration
def up
create_table :admins do |a|
a.string :name
end
create_table :users do |u|
u.integer :admin_id
end
create_table :listings do |l|
l.integer :admin_id
end
end
def down
drop_table :listings
drop_table :users
drop_table :admins
end
end
如果這不是你正在尋找的,那麼請澄清你的問題。
這些各種各樣的基本問題的信息,可得:http://guides.rubyonrails.org/
0
類管理<的ActiveRecord :: Base的
has_many :users
has_many :listings
末
類用戶< ActiveReecord :: Base的
belongs_to :admin
結束
類上市< ActiveReecord :: Base的
belongs_to :admin
末
相關問題
- 1. Ruby on Rails模型關聯
- 2. Ruby on Rails的:用戶模型關聯的應用和遷移
- 3. Ruby on Rails,用戶模型和活動管理查詢
- 4. Ruby on Rails的模型關聯
- 5. Ruby on Rails模型關係
- 6. Ruby on Rails關係模型
- 7. Ruby on Rails - 模型關係
- 8. Ruby on Rails與傳統數據庫的無表模型關聯
- 9. Ruby on Rails的,命名空間,模型和many-to-many關聯
- 10. Ruby on Rails - 多對一類型關聯
- 11. Ruby on Rails中的關聯
- 12. Ruby on Rails - 可選關聯?
- 13. Ruby on Rails雙向關聯
- 14. Ruby on Rails:使用belongs_to關聯創建模型條目
- 15. 添加評論到用戶和發表的模型(Ruby on Rails)
- 16. Ruby on Rails用戶列表列
- 17. Ruby on Rails中的表關聯
- 18. Ruby on Rails的連接表關聯
- 19. Ruby on Rails的 - 代表上has_and_belongs_to_many關聯
- 20. 屬於關聯表架構Ruby on Rails
- 21. Ruby on Rails模型重用
- 22. 使用Ruby on Rails模型
- 23. Ruby on rails:無法保存與Devise用戶關聯的配置文件模型
- 24. 模型Ruby on Rails中的關係
- 25. 多個Ruby on Rails模型關係
- 26. Ruby on Rails中的模型關係
- 27. Ruby On Rails ORM模型關係
- 28. 在Ruby on Rails中獲取模型及其關聯的JSON
- 29. Ruby on Rails的 - 驗證與關聯的模型屬性之
- 30. Ruby on Rails的增加模型的關聯
你有沒有考慮[閱讀文檔(http://guides.rubyonrails.org/association_basics.html),或者做一些研究在問之前? – DevMarwen