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

find_or_create_by doesn't call &block, in case it does "find"

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

      This feature was added in https://github.com/mongoid/mongoid/pull/678

      X.find_or_initialize_by(a: a, b: b, c: c) do |x|
        puts x
      end
      

      It only runs through the block on initialize (or create, if find_or_create_by is used).

      The related code in finders.rb is

      def find_or(method, attrs = {}, &block)
        first(:conditions => attrs) || send(method, attrs, &block)
      end
      

      Shouldn't the block variable pass on to the finder as well?

            Assignee:
            Unassigned Unassigned
            Reporter:
            Gurpartap Gurpartap [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: