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

Fetching attributes of Class not logical #145

Closed
2 tasks
thomaswitt opened this issue Dec 23, 2024 · 3 comments · Fixed by #146
Closed
2 tasks

Fetching attributes of Class not logical #145

thomaswitt opened this issue Dec 23, 2024 · 3 comments · Fixed by #146
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged.

Comments

@thomaswitt
Copy link

thomaswitt commented Dec 23, 2024

Describe the feature

One would assume that getting all keys of a Model based on aws-record works via ClassName.attributes.keys. It actually is ClassName.attributes.attributes.keys:

>> Account.attributes.keys
`<main>': undefined method `keys' for an instance of Aws::Record::ModelAttributes (NoMethodError)
>> Account.attributes.attributes.keys
=>
[:hash_key,
[…]
>> Account.new.attributes
`<main>': undefined method `attributes' for an instance of Account (NoMethodError)

ClassName.attributes returns more of an internal data structure.

Use Case

To know the attributes of a Model.

Proposed Solution

Both methods should be supported e.g.:

  • ClassName.new.attributes.keys
  • ClassName.attributes.keys

If you want to make life easier for people who come from activerecord, you might also want to support the method attribute_names

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

aws-sdk-ruby-record version used

latest

Environment details (OS name and version, etc.)

latest

@thomaswitt thomaswitt added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 23, 2024
@alextwoods
Copy link
Contributor

Thanks for submitting this - I do agree thats a little bit of a sharp edge. However, we can't change the behavior of the .attributes method without it being a breaking change.

We could instead add a .keys method to the ModelAttributes class to support ClassName.attributes.keys and add an #attributes instance method as well. We could also fairly easily add a .attribute_names method at the class/instance level.

@thomaswitt
Copy link
Author

@alextwoods Maybe a bit of documentation also does the job. And adding .attribute_names would align it with other Rails standards and not break anything.

Copy link

github-actions bot commented Jan 2, 2025

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants