Skip to content

Rails 5 belongs_to association behavior overridden #128

Description

@jmhooper

In Rails 5 belongs to associations are required by default. For some reason, after adding delayed_job_active_record to my Gemfile the presence of associated records was no longer required.

Here's how this can be reproduced:

  • Generate a new rails app with rails 5.0.0.rc1.
  • Generate 2 models that share a relationship:
class MyModel < ApplicationRecord
  belongs_to :my_related_model # This should imply a presence validation in Rails 5
end

class MyRelatedModel < ApplicationRecord
  has_many :my_models
end
  • Check that the presence of a MyRelatedModel is required for a valid MyModel
m = MyModel.new
m.valid? #=> false
m.errors.full_messages #=> ["My related model must exist"]
  • Add delayed_job_active_record to the Gemfile and run through the installation instructions in the delayed_job README
gem "delayed_job_active_record"
$ bundle install
$ rails generate delayed_job:active_record
$ rake db:migrate
  • Check that the presence of a MyRelatedModel is required for a valid MyModel
m = MyModel.new
m.valid? #=> true
m.errors.full_messages #=> []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions