ActiveRecord Parity: Support Simple Form in Mongoid

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Integrations, Rails
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
            Reporter:
            Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 1 week
                1w
                Remaining:
                Remaining Estimate - 1 week
                1w
                Logged:
                Time Spent - Not Specified
                Not Specified