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

V3.0 single table inheritance fails #112

Closed
danlewis opened this issue Dec 16, 2014 · 1 comment · Fixed by #159
Closed

V3.0 single table inheritance fails #112

danlewis opened this issue Dec 16, 2014 · 1 comment · Fixed by #159

Comments

@danlewis
Copy link

I have the following query on a model with single table inheritance (EmailAssignment is a subclass of MessageAssignment)
EmailAssignment.search_for(nil).page(1)

Version 2.7.1 worked fine generating the following query:
EmailAssignment Load (0.6ms) SELECT "message_assignments".* FROM "message_assignments" WHERE "message_assignments"."type" IN ('EmailAssignment') ORDER BY id DESC LIMIT 24 OFFSET 0

Version 3.0 however generates the following query which returns unwanted results.
MessageAssignment Load (0.7ms) SELECT "message_assignments".* FROM "message_assignments" ORDER BY id DESC LIMIT 24 OFFSET 0

@wvanbergen
Copy link
Owner

We never officially supported single table inheritance; i.e. there's no tests covering this functionality. Apparently it worked by luck because ActiveRecord's magic was appending the WHERE clause to our query.

I am not against supporting this, but it's unlikely I will have time to work on this anytime soon.

domcleal added a commit to domcleal/scoped_search that referenced this issue Jan 10, 2017
With an STI parent and subclass, calling `Parent.where` within a named
scope (i.e. `search_for`) in Rails 5+ now correctly returns all parent
and subclass records. When calling `Subclass.search_for`, this would
return unexpected results from other subclasses.

Querying the class that the scope was called on ensures the result is
limited to that class, restoring very basic STI support.

Fixes wvanbergen#112
domcleal added a commit to domcleal/scoped_search that referenced this issue Mar 23, 2017
With an STI parent and subclass, calling `Parent.where` within a named
scope (i.e. `search_for`) in Rails 5+ now correctly returns all parent
and subclass records. When calling `Subclass.search_for`, this would
return unexpected results from other subclasses.

Querying the class that the scope was called on ensures the result is
limited to that class, restoring very basic STI support.

Fixes wvanbergen#112
domcleal added a commit to domcleal/scoped_search that referenced this issue Mar 29, 2017
With an STI parent and subclass, calling `Parent.where` within a named
scope (i.e. `search_for`) in Rails 5+ now correctly returns all parent
and subclass records. When calling `Subclass.search_for`, this would
return unexpected results from other subclasses.

Querying the class that the scope was called on ensures the result is
limited to that class, restoring very basic STI support.

Fixes wvanbergen#112
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

Successfully merging a pull request may close this issue.

2 participants