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
last
method always returns a hash
#380
Comments
@gizotti confirmed. I have this bug too 👍
|
@davydovanton do you know where I can start looking for it? I'd love to dive into this one. |
@gizotti it's a problem of /cc @solnic, @flash-gordon and @AMHOL |
This won't be fixed in rom because it's not a bug in rom. See here for more info. |
FWIW I don't think that having |
@solnic fair enough :) Thanks for the reply. @davydovanton @jodosha, would it be worth implementing a "fix" on |
@solnic I understand right that now you prefer to use something like |
@davydovanton we have users.one # returns first struct based on default by-pk sorting
users.reverse.one # returns last struct based on default by-pk sorting |
You're right, But here we have another problem. The line To recap: For me Thanks 😄 |
@jodosha yeah you could just do this: def first
root.limit(1).one
end
def last
root.limit(1).reverse.one
end This will make sure you only fetch a single tuple, and it uses default ordering by pk. |
@solnic Thanks for the quick reply. We'll document this. |
Cross referencing rom-rb/rom-sql#64 |
We're working on documenting this, but I wonder if we can't do something in the code to help avoid this. Before
(I originally wrote this comment on the documentation fix, but it belongs here instead) If it's too late for any of these, that's fine. Just thought I'd bring it up :) |
@cllns IMO the second would be the way to go. If we remove those methods we would just end up making people write their own Now, when they are writing their own queries inside their repos I think we should enocurage Does that make sense? |
Yes, that makes sense @gizotti. Thanks for your feedback. I'm not sure of how the internals work here, so we'll @jodosha's input. I'm not sure if 2) is easily implementable. Also we might not be able to get any changes in to We're interested in hearing what others think is the right course of action as well :) |
@cllns about the second point: I think we need to use |
Maybe! We can discuss, if that option is feasible and we decide to go for it :) |
Folks, I went straight with the refactoring regarding The reason why this is a good idea is simple: it removes But please note that this GH issue is NOT about This is about a Now the "fix" for this is documenting the use case in the description of this PR: fetch the most recent post (as instance of |
@cllns I assigned this to you as you're working on the documentation for this. Can we get a PR out in a couple of days? Thank you! |
Any progress on this, @cllns ? |
Guys, I'm getting started with hanami, and this issue confused me very much. Does anyone work on it? I can do, if there are no volunteers. |
@Mehonoshin Sorry you ran into this issue. Yes, please open a PR :) <3 |
FYI we started working on rom-4 and I already ported auto-map/struct feature from repository to rom core and now this works consistently: [5] pry(main)> users = rom.relations[:users]
[6] pry(main)> users.with(auto_struct: true).first
=> #<ROM::Struct::User id=1 name="Joe Dane">
[7] pry(main)> users.with(auto_struct: true).last
=> #<ROM::Struct::User id=1 name="Joe Dane"> This means that hanami will be able to enable auto-map/struct for its relations and it'll work consistently. Furthermore, you'll be able to rely on built-in rom structs, as we added a feature where you can provide your own namespace and base struct class, which will be used to infer structs automatically and use your struct class as the base. You'll be able to either rely on inferred attributes, or define them explicitly, up to you. |
I have the following repository:
The
newest_post
method will always return aHash
instead of anPost
instance.If I change
last
tofirst
, I get aPost
instance as I want.I have no clue where to start looking for the problem. If someone could give me a clue, I can try to fix this one myself.
The text was updated successfully, but these errors were encountered: