I am working on a new site for a client creating an activity feed utilizing getstream.io. With this activity feed I am sending over actions like A commented on B, C posted D, E Rated F and so on…
Each of those things are different data types though (Comment, BlogPost, Rating, etc).
With the activity feed from getstream, I’d then have a list of these objects coming back like Comment:1234, BlogPost:25, Rating:34… Everything after the : is the ID of the object (typically).
Querying with SS ORM normally you would have to do three separate queries or at least two in this case -
Comment::get()->filter(['ID' =>[1,2,3...]]); SiteTree::get().... Rating::get()... or DataObject::get()->filter(['ClassName' => 'Comment', 'ID'=>[1,2,3]])->filter(['ClassName'=>'Rating', ID=>.... SiteTree::get()...
I am wondering if there is a better way to query for random data types more efficiently. One option I could do is create a table of all objects with a unique ID with a has_one relationship to the actual object which is polymorphic back to DataObject, this would then give me a central spot to query all objects. Another is using raw sql with joins getting just the data I need but would be extremely painful to write.
Wondering if there is a faster/better way to do this so that way I can them template out the objects based off of their type in the views.