Question

I'm trying to understand the best way to handle polymorphic relationships in rails and angular. I have a polymorphic tasks table. What is the best way to handle this on the data side so that the right tasks get pulled based on the object I am dealing with? For instance I have a table called "Patients" and each patient can have tasks assigned to them. Do I package the data up in rails and then send it to angular? Do I package that data in each controller that I am currently in (so patient pulls the correct tasks for the patient I am dealing with)? I'm really confused on how best to go about this. Any help is much appreciated.

Was it helpful?

Solution

I'm not familiar with Rails but the same issue exists if you use PHP or Java or whatever else on the back-end. The issue is basically do I want to do JOINS and parse through data on the server side or on the client side. Basically there's no absolutely right answer here, it really depends on the use case. Generally speaking you want to do your heavy lifting on the server side, so if you expect to have a ton of data to parse you don't want to leave that up to a client (think mobile processor). That said if you're dealing with say a few thousand records and not 100,000 then some of the work can be done client side and can reduce server round trips. The problem is you need to have all of the data client side in that case and you need to rely on the variable client side processor.

For small projects I feel like doing some of this client side ends up being much easier and doesn't have such a performance cost that it's not worth doing. Just my 2 cents.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top