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

popular_tags on relation #32

Open
jonnysperber opened this issue Aug 28, 2012 · 0 comments
Open

popular_tags on relation #32

jonnysperber opened this issue Aug 28, 2012 · 0 comments

Comments

@jonnysperber
Copy link

Calling popular_tags on a model class works flawless, but it seems not possible to call it on a relation or scope.
My model is called business and has (rocket)tags. If I do something like

@businesses = Business.near(lat,lng)

And then call

@businesses.popular_tags

to get the tag_cloud for this subset of entities, i get the following exception:

PGError: ERROR:  subquery has too many columns
LINE 1: ...e_type" = 'Business' AND "taggings"."taggable_id" IN (SELECT...
                                                             ^
: SELECT COUNT(*) FROM (SELECT count("tags"."id") AS tags_count, tags.* FROM "tags" INNER JOIN "taggings" ON "taggings"."tag_id" = "tags"."id" WHERE "taggings"."taggable_type" = 'Business' AND "taggings"."taggable_id" IN (SELECT  businesses.*, 6371.0 * 2 * ASIN(SQRT(POWER(SIN((52.5408134 - businesses.latitude) * PI() / 180 / 2), 2) + COS(52.5408134 * PI() / 180) * COS(businesses.latitude * PI() / 180) * POWER(SIN((13.4155842 - businesses.longitude) * PI() / 180 / 2), 2) )) AS distance, CAST(DEGREES(ATAN2( RADIANS(businesses.longitude - 13.4155842), RADIANS(businesses.latitude - 52.5408134))) + 360 AS decimal) % 360 AS bearing, "businesses"."id" FROM "businesses"  WHERE (6371.0 * 2 * ASIN(SQRT(POWER(SIN((52.5408134 - businesses.latitude) * PI() / 180 / 2), 2) + COS(52.5408134 * PI() / 180) * COS(businesses.latitude * PI() / 180) * POWER(SIN((13.4155842 - businesses.longitude) * PI() / 180 / 2), 2) )) <= 50) ORDER BY distance LIMIT 9 OFFSET 0) GROUP BY "tags"."id", "tags"."name" ORDER BY tags_count desc) tags

The SQL is not correct, because a IN may not have more than one selected attribute. I don't know though how to rewrite the query correctly in the mind of rocket_tag. Any idea? Is this a error at all or am I using rocket_tags incorrectly. There has to be a way to achieve tag_cloud for subsets.

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

1 participant