Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SCI with polymorph #322

Closed
b0c1 opened this Issue Oct 3, 2011 · 3 comments

Comments

Projects
None yet
4 participants

b0c1 commented Oct 3, 2011

Hi!

I try to do a following:

class GalleryItem
include MongoMapper::Document
belongs_to :gallery_album
key :text, Hash

timestamps!
auto_increment!
end

class TextGalleryItem < GalleryItem
key :type, String, :default => 'static'
many :posts, :as => :article_parent
end

(first I try to one :post, :as => :article_parent)

class Post
include MongoMapper::Document
....
belongs_to :article_parent, :polymorphic => true
....
end

And after that I create the Post. In the post the data is ok:
article_parent_id = 4e88ef382692e71dc400025f
article_parent_type = TextGalleryItem

TextGalleryItem:
_id = 4e88ef382692e71dc400025f
_type = TextGalleryItem

After that I try:
text_gallery_item.posts.all

result: []

(maybe the it's try to find in the text_gallery_items table not gallery_items etc...)

Any idea?

bogn commented Oct 4, 2011

Funny, I have a very similar problem and I'm trying to debug it for a while now and wanted to post an issue today.

The problem at my side is mostly the same, the many association (in my case it's embedded) on the subclass returns either an empty array or only BSON::UnorderedHash objects (in production). Please see the gist to see the involved classes and the scenario https://gist.github.com/1261606. As stated in the gist, the minimal example behaves correctly in the mmconsole, but not in the rails console or the app itself.

ruby-1.9.2-p180
rails (3.0.9)
bson (1.3.1)
bson_ext (1.3.1)
json (1.5.4)
json_pure (1.5.4)
mongo (1.3.1)
mongo_mapper (0.9.2)

Same with
bson (1.4.0)
bson_ext (1.4.0)
json_pure (1.6.1)
json (1.6.1)
mongo (1.4.0)

Seconded! I'm encountering the same issue and it is really, really annoying.

Contributor

brianhempel commented Nov 25, 2011

(Reformatted with syntax highlighting.)


Hi!

I try to do a following:

class GalleryItem
  include MongoMapper::Document
  belongs_to :gallery_album
  key :text, Hash

  timestamps!
  auto_increment!
end

class TextGalleryItem < GalleryItem
  key :type, String, :default => 'static'
  many :posts, :as => :article_parent
end

(first I try to one :post, :as => :article_parent)

class Post
  include MongoMapper::Document
  # ...
  belongs_to :article_parent, :polymorphic => true
  # ...
end

And after that I create the Post. In the post the data is ok:

article_parent_id = 4e88ef382692e71dc400025f
article_parent_type = TextGalleryItem

TextGalleryItem:

_id = 4e88ef382692e71dc400025f
_type = TextGalleryItem

After that I try:

text_gallery_item.posts.all

result: []

(maybe the it's try to find in the text_gallery_items table not gallery_items etc...)

Any idea?

@cheald cheald closed this in 980be10 Jul 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment