Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Problems with polymorphic models? #155

Open
andreasklinger opened this issue May 13, 2014 · 2 comments
Open

Problems with polymorphic models? #155

andreasklinger opened this issue May 13, 2014 · 2 comments

Comments

@andreasklinger
Copy link

If you use schema_plus together with friendly_id it tries to create foreign_keys for non-existing relations.

PG::UndefinedTable: ERROR:  relation "sluggables" does not exist

Solution is

 t.integer  :sluggable_id,   :null => false, :foreign_key => false

But it feels like this is a bug handling polymorphic relations

More info: norman/friendly_id#552 (comment)

@smudge
Copy link

smudge commented Jun 1, 2014

Seeing this as well. This fails:

t.string :resource_id,   null: false
t.string :resource_type, null: false

This works:

t.string :resource_id,   null: false, :foreign_key => false
t.string :resource_type, null: false

A fix might be to recognize the [thing]_id:integer [thing]_type:string pattern and not attempt to create the foreign key. I can't think of anything more accurate since the polymorphic relation is defined in the model class, not in the migration.

@ronen
Copy link
Member

ronen commented Jun 1, 2014

@smudge that does seem like a reasonable solution, No time for me to do it myself right now but I'd be happy to accept a PR, should somebody want to code it up. (it should support :foreign_key => yes to force the foreign key anyway.) (and of course should included tests!)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants