Skip to content

Issue with PR #1639 #1640

@georgempla

Description

@georgempla

Bug: Shipping a project fails with postable can't be blank

Introduced by: #1639 (commit 778654b)

Cause:The commit added validates :postable_id, presence: true to Post. This validation fires before Rails has a chance to persist the associated Post::ShipEvent and assign it an id. Since postable_id is still nil at validation time (the record hasn't been saved yet), the validation fails and the whole transaction is aborted.

Fix: Replace the column-level validations with an association-level one:

# Remove these:
validates :postable_id, presence: true
validates :postable_type, presence: true

# Add this instead:
validates :postable, presence: true

This validates the object reference rather than the raw foreign key column, so it works correctly with delegated_type's autosave behaviour.

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