Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2857

Problems with collection name

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.3
    • Affects Version/s: None
    • Component/s: None

      Let's say I have 3 classes. https://gist.github.com/chamnap/5024664

      class A; end
      class B; end
      class Book
        include Mongoid::Document
      end
      

      I want to define two new classes named A::Book and B::Book based on Book. Then, i change their collection's name.

      a_book = A.const_set(:Book, Class.new(Book))
      a_book.store_in collection: 'a_books'
       
      b_book = B.const_set(:Book, Class.new(Book))
      b_book.store_in collection: 'b_books'
       
      A::Book.collection_name  #:b_books, it should return :a_books, right?
      B::Book.collection_name  #:b_books
      

      It turns out #collection_name returns wrong information. However, if I call #store_in, then call #collection_name, it just works fine. Why it's like that?

      a_book = A.const_set(:Book, Class.new(Book))
      a_book.store_in collection: 'a_books'
      A::Book.collection_name  #:a_books, need to call this method after set.
       
      b_book = B.const_set(:Book, Class.new(Book))
      b_book.store_in collection: 'b_books'
      B::Book.collection_name  #:b_books, need to call this method after set.
       
      A::Book.collection_name  #:a_books, then it displays correctly.
      B::Book.collection_name  #:b_books, the same here
      

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            chamnap chamnap
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: