-
Notifications
You must be signed in to change notification settings - Fork 274
Add: has_one(chainable: true) option #1422
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
Conversation
| #has_many http://www.rubydoc.info/gems/neo4j/Neo4j/ActiveNode/HasN/ClassMethods#has_many-instance_method | ||
| and | ||
| :ref:`#has_one <Neo4j/ActiveNode/HasN/ClassMethods#has_one>` | ||
| #has_one http://www.rubydoc.info/gems/neo4j/Neo4j/ActiveNode/HasN/ClassMethods#has_one-instance_method |
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.
Currently, in the docs this see also block links to nothing. I've updated it with appropriate links to the API on rubydoc.
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.
Thanks! I had actually written some code a while back to turn the YARD documentation into rst files for readthedocs (you can see the rst formatting on rubydoc.info), but re-implementing rubydoc.info was probably largely a waste of my time ;) . I think these were links to that internal API documentation, but glad to have these fixed now
| end | ||
|
|
||
| def define_has_one_getter(name) | ||
| def define_has_one_getter(name) # rubocop:disable Metrics/PerceivedComplexity |
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.
Rubocop was failing this with PerceivedComplexity as too high. I didn't know what to do with that, so I suppressed the warning to make it pass 😕 ...
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.
It could probably just do with an extraction of a method. I'll fix it and link to the commit here
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.
Meh, not the best: 1122ee7
Codecov Report
@@ Coverage Diff @@
## master #1422 +/- ##
=========================================
Coverage ? 96.86%
=========================================
Files ? 205
Lines ? 12455
Branches ? 0
=========================================
Hits ? 12065
Misses ? 390
Partials ? 0
Continue to review full report at Codecov.
|
|
I could see the use for this, but what about: comment.association_proxy(:post).authorI think I like your solution better because it's a bit more obvious, but I wanted to mention that |
|
We could even probably |
|
I find having the method name describe the function rather then the argument describe the function to be more readable and intuitive. The decision to have the result wrapped vs unwrapped seems to be fundamentally a param choice, rather than a method choice. For example: vs |
|
Especially when I'm already conditioned by Neo4j to see an association chain as |
|
Yeah, I actually agree a lot. We actually have two options for specifying object.association(optional: true)
object.optional(:association)I prefer the first one as well. I'll have a look through this PR this, thanks! |
|
Looks great. Since this isn't a bugfix but a backwards compatible change I'll release this in #1419 is indeed a breaking change, though I doubt it will affect anybody so I'm tempted to just put it into 8.3 (especially since we have good exceptions around it) |
| #has_many http://www.rubydoc.info/gems/neo4j/Neo4j/ActiveNode/HasN/ClassMethods#has_many-instance_method | ||
| and | ||
| :ref:`#has_one <Neo4j/ActiveNode/HasN/ClassMethods#has_one>` | ||
| #has_one http://www.rubydoc.info/gems/neo4j/Neo4j/ActiveNode/HasN/ClassMethods#has_one-instance_method |
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.
Thanks! I had actually written some code a while back to turn the YARD documentation into rst files for readthedocs (you can see the rst formatting on rubydoc.info), but re-implementing rubydoc.info was probably largely a waste of my time ;) . I think these were links to that internal API documentation, but glad to have these fixed now
| end | ||
|
|
||
| def define_has_one_getter(name) | ||
| def define_has_one_getter(name) # rubocop:disable Metrics/PerceivedComplexity |
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.
It could probably just do with an extraction of a method. I'll fix it and link to the commit here
|
|
||
| describe 'with chainable: true option' do | ||
| it 'returns an empty association proxy object' do | ||
| expect(unsaved_node.parent(chainable: true).inspect).to eq '#<AssociationProxy HasOneB#parent []>' |
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.
I think this would be a bit better as:
expect(unsaved_node.parent(chainable: true)).to be_a Neo4j::ActiveNode::HasN::AssociationProxy
I can make that change
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.
|
I imagine the semantic versioning standard was created specifically to prevent an update like this from being released as a minor point increase. Major updates pretty obviously demand someone's attention. I imagine the little updates are the ones that break something because no one expects them to. Definitely understand the temptation, but can't say I support it. |
|
Yeah, that's certainly fair, and I can change it to Since I just support the gems in my spare time, I generally don't have the ability to keep track of a number of changes which would get bundled into a major / minor release. It's much easier to simply upgrade the version whenever any change, big or small, comes in. If that's a breaking change, that means that the version could start to go up to I also worry about having people upgrade major versions and them being completely non-events because something that was released was technically a breaking change, but only affects users who would be using the feature in a non-typical way. That may lead them to see things as being broken in the other direction (that major versions are upgraded without much reason). This fear probably comes from a notion that big / major version number changes are supposed to be a "big deal" and generally come with big changes (each version of iPhone/iOS, HTTP 1 to HTTP 2, Web 2.0, etc...) But on balance I think it's probably better to upgrade versions strictly based on semver. If it becomes something that people are mentioning I could probably have a note in the |
|
Yeah I get that. If you wanted, I think it would be possible to achieve both by creating a duel versioning scheme (e.g. Google Chrome does that). The semver version is what people would spec against. The branding(?) version is what people could look at to get a sense of how large the update is. In the readme you might put: Neo4jrb 3semver 13.4.3 Of course you'd need to explain this. And ya, large open source projects with paid maintainers will manage releases to limit the semver point increase, but I think its totally ok for volunteer projects to ignore that. I don't see anything wrong with the version blowing up to 20/30/40.x.x -- and if devs do have a problem with it, I imagine they'll give feedback. At its core: ya, as a dev its annoying when a dependency demands your attention during an update and forces you to look at the changelog, but for breaking changes like this, people really should look at the changelog. This being said, you're doing a kick-ass job managing this repo as is, so ultimately, do what you gotta do. |
|
Yup, thanks ;) I think I'll just go with the simplest "upgrade whatever is appropriate" for each change for now, at least ;) I just realized I didn't release this as 8.3.0 previous, so I just did that now |
By default,
model.has_onecalls.firston the result. If the result isnil, this means the method is not chainable. I'd like to have the option of getting an association proxy back from ahas_onegetter. Having dug into the source, I see thathas_onemethods actually take arguments and options, and one of those options (rel_length) can return a chainable result, butrel_lengthis not an intuitive argument to pass if you specifically want a chainable result.rel_lengthmust have a non-integer value to return an association proxy (e.g.rel_length: '') which adds to the complexity / is ugly.This pull introduces/changes:
chainable: trueoption tohas_onemethods that returns an association proxy instead of an ActiveNode objectPings:
@cheerfulstoic
@subvertallchris