RoG에 Mongodb 데이터베이스가있는 응용 프로그램이 있습니다. 몽고 매퍼를 사용합니다. 모델 post.rb
몽고 이드 쿼리
class Post
include Mongoid::Document
field :title, :type => String
field :text, :type => String
embeds_many :comments
end
모델 comment.rb
일부 의견이 게시물 다음 구조가 데이터베이스에서
class Comment
include Mongoid::Document
field :name, :type => String
field :content, :type => String
embedded_in :post, :inverse_of => :comments
end
: 데이터베이스와 몇 게시물 예를 들어
{
"_id": ObjectId("4ecbeacf65430f0cef000003"),
"comments": {
"0": {
"name": "my name",
"content": "example content",
"_id": ObjectId("4ecbead365430f0cef000005")
},
"1": {
"name": "some name",
"content": "example content",
"_id": ObjectId("4ecbead665430f0cef000007")
},
"2": {
"name": "some name",
"content": "example content",
"_id": ObjectId("4ecbeada65430f0cef000009")
}
},
"text": "example text",
"title": "example title"
}
그리고를했다 내 의견. 모든 게시물을 찾아야합니다 ("name": "my name"
). 즉, 모든 게시물을 편집 할 수 있어야합니다.
: 또한
, 나는 comments.name 필드에 인덱스를 추가 할을 Comments 객체가 객체의 배열이 아니어야합니까? 임의의 이름을 가진 하위 객체의 객체가 아닌가? 스키마 구조를 다시 살펴 보겠습니다. – Petrogad