リレーション
has_many / belongs_to / has_one
自動的に、リレーション用のカラムを作ってくれる
class BattleShip
has_many :mobile_suites
end
class MobileSuite
#battle_ship_idカラムが生成される
belongs_to :battle_ship
end
bson内部に子を内蔵する
embedすると、bson内に内蔵できる
class BattleShip
embeds_many :mobile_suites
end
class MobileSuite
#battle_ship_idカラムが生成される
embeded_in :battle_ship
field :name, type:String
end
{
_id:BSON("123455"),
mobile_suites[
{
_id:BSON("123456"),
name:"白いやつ"
}
]
}
内蔵した上でツリー状にする
embedして:cyclic => trueする
class BattleShip
embeds_many :battle_ships ,:cyclic => true
embeded_in :battle_ship ,:cyclic => true
end
```bson
{
_id:BSON("123455"),
battle_ships[
{
_id:BSON("123456"),
battle_ships[
{
_id:BSON("123457")
}
]
}
]
}