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

store_in macro with lambdas don't work as expected

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.3
    • Component/s: None
    • Labels:

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: