Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict includes to specific filters? #20

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

Restrict includes to specific filters? #20

vinnyglennon opened this issue Jan 5, 2014 · 3 comments

Comments

@vinnyglennon
Copy link

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

@cantino
Copy link
Contributor

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
Copy link

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

@cantino
Copy link
Contributor

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
Labels
None yet
Development

No branches or pull requests

3 participants