Open redbar0n opened 9 years ago
Thanks for reporting your issue! This is one of my 4 active issues. Use that link to check how soon your issue will be answered. Don't forget to check your issue against this project's CONTRIBUTING.md. Cheers.
Hi. Configuring :fields is meant for required fields. Hirb doesn't have a notion of optional fields and I wouldn't want to make this default. The underlying helper, ObjectTable is pretty tiny. You can extend ObjectTable to support an optional fields mode or write your own helper that allows for optional fields and configure hirb to use it. Let me know if you'd like to extend ObjectTable and I can keep this open
I'm not advocating for optional fields, I'm simply suggesting that Hirb should suspend its required fields when the user is explicitly telling ActiveRecord what fields he wants to select. Otherwise, as it is now, it breaks user expectation of the standard ActiveRecord functionality.
What I'm suggesting is that Hirb will ignore requiring all the fields specified by default (in hirb.yml) when the user is using a select statement to explicitly specify the required fields. Otherwise, the table output can work as normal and print the columns in the nice table layout (while simply pertaining to only the fields/columns specified in the select statement).
Doesn't that make sense?
This is definitely an issue. Hirb shouldn't require the regular attributes when using a select statement
+1
+1
A custom ActiveRecord select statement like
BlogEntry.select(:title,:url).group(:title,:url).having("count(*) > 1")
works fine without Hirb:
But when Hirb is enabled, and using hirb.yml, it will give an (unnecessary) missing attribute error. I say unnecessary because when I have specifically specified in the select statement the fields I'm interested in, I don't want the Hirb.yml definition (which I use as my default) to come back to bite me, like this:
Probably due to the way Hirb hard-enforces the hirb.yml.
My Hirb.yml file looks something like this:
Could you make it not hard-enforce hirb.yml, in case one wants to use custom select statements?