Skip to content

association with a class_name parameter #7

@keien

Description

@keien

Hi,

First of all, great gem! This is exactly what I needed for my Rails app.

Unfortunately, I had an issue with associations that have a different name than their class, for reversing relationships with two foreign keys from the same model. Here's what it looks like:

has_many :relationships, foreign_key: "subject_id", dependent: :delete_all
has_many :reverse_relationships, class_name: "Relationship",
                                             foreign_key: "target_id",
                                             dependent: :delete_all

I think it's a problem with the way you access the model class. As far as I know, this is what the gem does:

sub_model_class = :association_name.to_s.classify.constantize

Since ReverseRelationship is not a class, this gives me this error when using recuse_delete: NameError: uninitialized constant ReverseRelationship

It'd be great if you could have this working for associations that use class_name as well.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions