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

Feature request: default value on the :foreign_key attribute

      Hello, currently there's no way to set :default value for the :foreign_key attribute, and sometimes it may be useful.

      1. Usage
        class Post
        belongs_to :user, default: lambda {User.current.id}

        end

      1. Implementation
        Mongoid::Relations::Metadata.class_eval do
        def foreign_key_default_with_options
        self[:default] || foreign_key_default_without_options
        end
        alias_method_chain :foreign_key_default, :options
        end

            Assignee:
            Unassigned Unassigned
            Reporter:
            alexeypetrushin Alexey Petrushin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: