-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Hello, currently there's no way to set :default value for the :foreign_key attribute, and sometimes it may be useful.
- Usage
class Post
belongs_to :user, default: lambda {User.current.id}end
- 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