A has_many polymorphic association usually gets indexed like the following:
# The migration:
t.references :commentable, polymorphic: true, index: true
# Produces this in the schema:
add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type"
However, I have a has_one polymorphic association (see this question for the details). Is this index still useful? Combinations of posting_detail_type
and posting_detail_id
would be unique, as in only one of each would ever occur. So it seems to me that the index wouldn't be that useful.
What indexing should be used in this case? Just one on the posting_detail_type
column?