empty result set @activities = ...

33 views
Skip to first unread message

fugee ohu

unread,
Apr 3, 2016, 8:25:12 PM4/3/16
to Public Activity
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.all_follows, owner_type: "User")

this line of code returns an empty @activities object, my models are set up ok, PublicActivity::Activity.all returns all publicity, regardless of follows, the current_user is following one model with posts, I don't know why none of the posts are present in the object

Piotrek Okoński

unread,
Apr 4, 2016, 3:06:46 AM4/4/16
to fugee ohu, Public Activity
Try following conditions:

.where(owner_id: current_user.all_follows.pluck(:id))

On 4 April 2016 at 02:25, fugee ohu <fuge...@gmail.com> wrote:
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.all_follows, owner_type: "User")

this line of code returns an empty @activities object, my models are set up ok, PublicActivity::Activity.all returns all publicity, regardless of follows, the current_user is following one model with posts, I don't know why none of the posts are present in the object

--
You received this message because you are subscribed to the Google Groups "Public Activity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to public-activi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

fugee ohu

unread,
Apr 4, 2016, 3:57:45 AM4/4/16
to Public Activity, fuge...@gmail.com
what's pluck?

Piotrek Okoński

unread,
Apr 4, 2016, 4:00:40 AM4/4/16
to fugee ohu, Public Activity
Use Rails documentation to learn about methods and their usage: http://api.rubyonrails.org/, type the method name in the top left and you'll get the answer :)

fugee ohu

unread,
Apr 4, 2016, 4:08:10 AM4/4/16
to Public Activity, fuge...@gmail.com

What about the trailing owner_type: "User")
 

fugee ohu

unread,
Apr 4, 2016, 4:35:52 AM4/4/16
to Public Activity, fuge...@gmail.com


On Monday, April 4, 2016 at 3:06:46 AM UTC-4, Piotrek Okoński wrote:

That get's me this error

Cannot eagerly load the polymorphic association :followable

fugee ohu

unread,
Apr 5, 2016, 1:13:17 PM4/5/16
to Public Activity, fuge...@gmail.com


On Monday, April 4, 2016 at 3:06:46 AM UTC-4, Piotrek Okoński wrote:

Hey got it working I didn't need to use pluck I was getting an empty result set because I was using the wrong model type, my  followable model isn't User it's actually Profile Don't ask why I do that, I've been criticized pretty harshly for it, I thought might be leaving the door open for users to have multiple profiles which some would also call "personas"
Reply all
Reply to author
Forward
0 new messages