1

We have an app in Rails 4 (but soon to be Rails 5) that has a polymorphic log class that we inherited from a Django app.

In a traditional polymorphic relation, the objects would have source_type and source_id, which would be things like 'some_class' and 123.

In our little model, we have content_type and content_id which unfortunately map to two ints, where the int in content_type further points to a ContentType model that -- to further complicate things -- dont map to Rails-ey types ('some_type' but rather django-ey 'some type class'.

It's a mess.

Is there any way to override the value used in looking in a polymorphic association (e.g. instead of using 'some_class', use 11) -- but just for the association? There is an answer for a problem somewhat similar to ours, but it is 4 years old and it overrides association_class. We still use some of this strange Django voodoo elsewhere in our codebase, so overrides feel like they'd cause more problems than solve.

Mike Manfrin
  • 2,722
  • 2
  • 26
  • 41
  • It's not clear at all what the relationship is between the Django app and your app, and whether it even matters. Is there a reason this has a [django] tag? Is your Django app still relevant? Are you replacing or co-existing? In other words, can you refactor the Rails model to be more "Rails-ey"? – Mark Thomas Jun 29 '17 at 00:02
  • Also, it would help if you provide more actual context (i.e. code). What are your pertinent models or table structures? – Mark Thomas Jun 29 '17 at 00:04

0 Answers0