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

store_in macro with lambdas don't work as expected

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

      In the docs, there is an example of using lambdas with the store_in macro:

      class Band
      include Mongoid::Document
      store_in database: ->

      { Thread.current[:database] }

      end

      However, it does not work as expected:

      Thread.current[:database] = 'first'
      Band.database_name #=> :first
      Thread.current[:database] = 'second'
      Band.database_name #=> :first (when :second is expected)

      I believe this is because #database_name memoizes the name when it is called for the first time.

      Same thing happens for #collection_name as well.

            Assignee:
            durran Durran Jordan
            Reporter:
            jasoncheow jasoncheow
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: