- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我在处理我认为是基本关联的问题时遇到了问题。
我有一个 Game 模型和一个 Matchset 模型。
在游戏模型中是一个游戏列表。游戏只在游戏表中列出一次,但它们可以属于多个 Matchsets。
匹配集.rb -
has_many :games
对于 game.rb 我不确定我会放什么。我不想放 belongs_to 因为它属于许多匹配集,而不仅仅是一个。而且我认为我不想将 has_and_belongs_to_many 放在一起,因为匹配集不一定“属于”游戏,但也许我只是看错了。
示例:匹配组 1 包含游戏 1、3 和 5。匹配组 2 包含游戏 2 和 3。匹配组 3 包含游戏 3、4 和 5。
我的 Oracle SQL 背景和在我脑海中的 Matchset 表看起来像这样。
id | game_id
1 | 1
1 | 3
1 | 5
2 | 2
2 | 3
3 | 3
3 | 4
3 | 5
感谢任何帮助。
最佳答案
这些关系应该适合你:
class Game < ActiveRecord::Base
has_many :game_match_set_relations
has_many :match_sets, through: :game_match_set_relations
class MatchSet < ActiveRecord::Base
has_many :game_match_set_relations
has_many :games, through: :game_match_set_relations
class GameMatchSetRelation < ActiveRecord::Base
belongs_to :game
belongs_to :match_set
validates :game_id, presence: true
validates :match_set_id, presence: true
关于ruby-on-rails - rails 协会 - has_many 与 has_and_belongs_to_many,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19986237/
我需要查找两个模型之间的记录。 class Report has_and_belongs_to_many :groups end class Group has_and_belongs_to_
我正在尝试在我的 Rails 应用程序中设置 Employee 模型和 NetworkDrive 模型之间的 has_and_belongs_to_many 关系。 在 employee.rb 中我指
我在用户和项目之间建立了多对多关系,而且它工作得很好。但是我想在 mongoid 中模拟这种情况: db.projects.insert( { "name" : "Test project
我有两个实体、数据中心和项目之间的多对多链接表,在遗留代码中。我发现,这实际上是一对多的关系。 作为清理关系的第一步,我想放一个唯一索引在其中一个字段上。 现在我收到以下错误: has_and_bel
我有一组非常简单的 HABTM 模型 class Tag tag) end end end 现在一切正常,除了标签表中出现大量重复项。 我需要做什么才能避免标签表中出现重复(基于名
我试图弄清楚 rails 是如何决定命名一个表的。我不得不反复试验才能弄清楚。 该表最终被命名为 menu_categories_items .我想知道它是如何做到的。 楷模 # == Schema
我对 HABTM 与 Rails 3.2.11 的关联有点困惑。 我有一个图像模型: class Image false do |t| t.references :image
我有研讨会表和类别表。 车间模型: has_many :workshop_categories, dependent: :destroy has_many :categories, throu
我有两个模型,Conversation 和 Phones,它们彼此有_and_belongs_to_many 个。电话可以有很多对话,对话可以有很多电话(两个或更多)。 class Conversat
修复者:更改模型名称以匹配 Rails 命名约定 当我尝试将技能加入用户时出现以下错误: irb(main):006:0> user.skills ' from script/rai
我试图让 mongoid 保存关联,但我只能让一侧工作。如果我有以下测试。 test "should add a user as a follower when a user follows th
我的 Ruby On Rails 项目中的 has_and_belongs_to_many 关联有问题。 这是我的模型: class Store false, :force => true do |
c = Course.create name:"Math1", ?? 我试图弄清楚如何将这门类(class)与 has_and_belongs_to_many 的现有学生联系起来。下面是我的关联模式。
预订 has_and_belongs_to_many学生们 学生 has_and_belongs_to_many图书 在 BooksStudents 模型中,我想在商店中添加“状态”字段,如果它是租用
嗨,我在模型中使用 has_and_belongs_to_many。 我想为种类设置存在的 valitor。 并将每个核心的最大种类数设置为 3 class Core 'core_id', :ass
一般混淆 我有可以有 3 种类型的乐队。我读了 previous SO post处理这个问题的正确方法是几个步骤: 1) 带内.rb has_and_belongs_to_many :genres 2
我有 field 和照片的模型: class Venue 这是我的 Edit 和 Update 方法的
我不知道这是否是 oracle_enhanced 适配器的问题。我有: class Room []) end end 日志 Started POST "/manuals" for 127.0
我正在尝试在 Ruby on Rails 项目中执行以下操作: class FoodItem :food_categories end class FoodCategory :food_categ
我有一个模型 UseCases(大约 6.000 行)和 EducationalObjectives(大约 4.000 行)与 has_and_belongs_to_many(EducationalO
我是一名优秀的程序员,十分优秀!