Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add has_one scope support to virtual_delegate
This enhances virtual_delegates so that scopes added as part of a `has_one` relation are respected. Because of the changes, an implicit `limit = 1` was necessary to support the `has_one`, and the easiest way to accomplish that while still keeping `select_from_alias` in a similar form was to allow passing a block so the arel (prior to being converted to a string) could be updated. Also of note, `select_from_alias` also had a few changes to it beyond that: - The "query" is now built up from the scope on the model, not a raw arel_table from the to_ref model. - Instead of a `project`, we call a `.select` on the "query" (scope from the relation), which already has a similar arg structure, but allows us to remove the select_values properly before converting it to arel (happens right after the `.select`). We work with raw `Arel` after that. - The `table_alias` functionality is now done through the `from` clause, `from(to_table)` allows us to still keep the same alias functionality we had. Under the covers, this does the same thing, it is just previously the starting point was an `Arel::Table`, and now it is a `Arel::SelectManager`. The `Arel::Table` version ends up returning a `SelectManager` anyway, so what we are doing is functionally equivalent.
- Loading branch information