-
Notifications
You must be signed in to change notification settings - Fork 30
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
Allow nested attributes to be accessed #15
Conversation
the attributes are nested
access to nested attributes specified in the v2 API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsul This is very interesting. Thanks for starting the conversation.
I understand that we need a solution for this problem, but I think it would be best to implement something that allowed the user to do this:
time_entries = client.time_entries
time_entry = time_entries.first
expect(time_entry.project.name).to eq(project_name)
expect(time_entry.project.id).to eq(project_id)
In that scenario, we could load time_entry.project
with a Harvesting::Models::Project
instance and populate it with the right attributes.
What do you think?
d663821
to
570b9f5
Compare
@etagwerker how about now? Your approach was one we considered, but didn't land on initially, but seems easy enough to adopt. Did you imagine making model classes for things like |
570b9f5
to
6c62742
Compare
6c62742
to
2b7ff2f
Compare
@etagwerker @benphelps @mscottford can we get some response to this? Seems like a few PRs have stalled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsul This is great! One last thing, could you add some examples to README.md
?
Also, I'm open to ideas to improve documentation for this new behavior.
@etagwerker Updates made - what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current architecture of the
Base::attributed
method does not allow for access to nested attributes that are a part of the Harvest v2 API. We modified that method in a way that we thought aligned with your vision so that accessors can be dynamically created when nested attributes are passed in.For example:
The v2 API has
id
nested within a project object inTime Entries
, as opposed to having a top-levelproject_id
accessor like the current architecture assumes. The suggested change would create aproject_id
accessor by combining the top levelproject
key with each nested attribute.