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

ActiveRecord Parity: Fix SimpleForm f.association on Mongoid

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Integrations, Rails
    • None

      Background

      Simple Form is a widely-used gem with over 8000 stars on Github. The `f.association` syntax is broken Mongoid, which works with ActiveRecord. Refer to these issues:

      "Making Mongoid easier for new users" appears to be a topic the MongoDB team is interested in. Fixing issues which new users are likely to encounter when making new apps will increase user satisfaction.

      Possible Fix

      I was able to fix the #1609 with the following Monkey patch, This could be added to Mongoid's codebase with a @note comment on the methods to explain why they are needed. Alternatively, we could raise a patch to SimpleForm itself.

       

      module Mongoid
        module Association
          module Relatable
            def macro
              ''
            end
          end
          module Referenced
            class BelongsTo
              def macro
                :belongs_to
              end
            end
            class EmbeddedIn
              def macro
                :embedded_in
              end
            end
            class EmbedsOne
              def macro
                :embeds_one
              end
            end
            class EmbedsMany
              def macro
                :embeds_many
              end
            end
            class HasAndBelongsToMany
              def macro
                :has_and_belongs_to_many
              end
            end
            class HasMany
              def macro
                :has_many
              end
            end
            class HasOne
              def macro
                :has_one
              end
            end
          end
        end
      end
      

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: