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

The check to determine if the joined document is the correct type should be performed after _apply #179

Closed
phillips1012 opened this issue Feb 10, 2015 · 1 comment

Comments

@phillips1012
Copy link

If I want to do something like

.getJoin
  comments:
    _apply: (x) -> x.count()

It shouldn't throw this

Cannot coerce NUMBER to ARRAY

It'd be nice to see a fix to this, as I'd rather not load 300 objects into memory 10 times every single request.

@neumino
Copy link
Owner

neumino commented Feb 10, 2015

Hello @phillips1012

I just released 1.16.2 with a fix for that.
You have to pass an extra option _array: false if you do not want to coerce to an array.

Something like this in your case:

Posts.getJoin
    comments:
        _apply: (x) -> x.count()
        _array: false

The reason why thinky doesn't check the type itself is because you currently cannot bind a stream with do, and cannot do something like
r.branch(seq.typeOf().eq("STREAM"), seq.coerceTo("ARRAY"), seq) without having to compute twice seq (which can be expensive).

If streams are automatically coerce to arrays, this would remove the need for _array but this is not yet implemented - rethinkdb/rethinkdb#2721

Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants