ManageIQ / ManageIQ/activerecord-virtual_attributes

Support virtual_attribute => another_attribute

Open
#121 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Ruby
Stars
10
Forks
11
PR merge metrics
No merged PRs in 30d

Description

This is written as a bug, but is probably an RFE. Or at least a request to add a warning.

## Overview

For uses clauses, we currently don't support nested attributes:

```ruby
class Book
has_and_belongs_to_many :co_authors, :class_name => "Author"
end

class Author
virtual_has_one :book_with_most_bookmarks, :uses => {:books => :bookmarks}
virtual_has_many :famous_co_authors, :uses => {:book_with_most_bookmarks => :co_authors} ## HERE
end
```

## Issue

Above, it is not obvious what the value of the includes should be:

- option 1: `{:books => {:bookmarks => :co_authors}}`
- option 2: `{:books => [:bookmarks, :co_authors]}`

Currently we ignore the target, so we basically read the definition as the following:

```ruby
class Author
virtual_has_many :famous_co_authors, :uses => :book_with_most_bookmarks
end
```

We currently do not have the need to support this feature, but I noticed it while writing tests for another issue.

## Options

We have a few ways to move forward:

- continue ignoring the target
(developer can write it a different way)
- add a warning
- throw an exception
- look at the klass of the association and determine the best way
(this involves introspection of another class which has caused class loader deadlocks in the past)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the virtual_has_many and virtual_has_one handling of the :uses option and reproduce the nested-attribute case from the Ruby examples in a test. First resolve whether the project should ignore the target, warn, raise, or infer through association introspection; done requires an agreed behavior and a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.