Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Restrict includes to specific filters? #20

Open
vinnyglennon opened this Issue Jan 5, 2014 · 3 comments

Comments

Projects
None yet
3 participants

I got a user with posts. Some posts are not published.

If I do user.json?include=posts this will give me all posts for that user. Is it possible to restrict it to just posts that are published?

Best,
Vinny

Member

cantino commented Jan 6, 2014

Hey @vinnyglennon,

There are two options. One would be to create a new association on User called published_posts and then point Brainstem at that. That's probably easiest. You can also give Brainstem a lambda when using association and return anything you want. This will be less efficient because it can't eager load the way it does with associations, but it would work.

Finally, if you're interested, I think allowing filters on associations would be a great general addition to the next version of Brainstem.

45sound commented Jan 8, 2014

Hey @cantino,
Using a published_posts association works perfectly.
Using a lambda gives an additional problem that the response cannot be cached with memcache, as ruby cannot serialize Procs.
V

Member

cantino commented Jan 8, 2014

Hey @45sound, could you show me an example of how you were using the lambdas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment