ruby on rails - how to avoid polymorphic associations -


You have to implement a news feed appearing in the social network, formerly Facebook is currently using the news class I have a polymorphic allocation, which can be any kind of image, comment, friendship, group membership, etc. Whenever an object is created, as the news is made it is working fine with the AR (activists), but when I turn to DM (datamaker) or sequel, both can have trouble because Both have not supported the theatrical associations dramatically and have discouraged its use.

There is a separate solution that is used to merge all the various tables in order to use a large SQL section with lots of unions, which should be considered as news. But there are some drawbacks in this, especially the performance will be horrible.

So I wonder if whenever you have to solve without the Polyemorphic Association, there are good performance and no other drawbacks, such as the possibility of adding meta data to the news?

Disclaimer: I am the chief developer of the next sequel.

The best way to go about it depends largely on how you should know about the types of things you want to do with the data, to be the foreign key column for all possible relationships. This is how:

  News: ID ... (other column) image_id comment_with_friend_idi_group_memberships_id  

creating a common foreign key versus like this and the name of a class Save in A display Tv no difference. For sluggish loading, you choose only one foreign key field which is not zero / zero, and select the appropriate collaboration to load. For eager loading of Q-per-table, you load all the organizations at once. It is also more flexible that you can enthusiastically load using JOIN, which is not possible with the polymorphic approach, besides, you get the benefit of the actual referential integrity.

One downside is that if you want to add more types of cooperation in the future, you need to add the foreign key to the table.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -