-
Notifications
You must be signed in to change notification settings - Fork 14
Adopt modern Active Record patterns #63
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
…n for attribute names are retained. So the short form for New York is now NY instead of ny. test/model/Author, Book, and Venue now have those strtoupper() workarounds in getter/setter methods removed as it's done in Model.php
…rcased in Model.php in order to be case insensitive.
…n for attribute names are retained. So the short form for New York is now NY instead of ny. test/model/Author, Book, and Venue now have those strtoupper() workarounds in getter/setter methods removed as it's done in Model.php
…rcased in Model.php in order to be case insensitive.
# Conflicts: # lib/Model.php
…cord # Conflicts: # test/ActiveRecordTest.php # test/models/Book.php
…Disable it so that regression does not timeout.
Authors table now has a column that is camel cased: firstName Added tests that demonstrate case insensitivity when accessing this firstName column
- Correct link to contributing.md
…vity() is enough.
…cord # Conflicts: # composer.json # scripts/TestCommand.php
…cord into RubyLikeFind # Conflicts: # composer.json # scripts/TestCommand.php
…cord into RubyLikeFind # Conflicts: # lib/Model.php
|
I've done a quick review of this large PR. Good job! That was a lot of work. A spec issue that comes to mind is when clauses are repeated. Should: Author::select('A')->select('B')->findselect only B (this is what currently happens), throw an error, or select columns A and B? But repeated where clauses act differently: Author::where('A')->where('B')->findit does where('A and B'). But why the inconsistency with select which replaces A with B? This should be specified in the documentation. A similar reasoning and documentation exercise would have to be done for having, group, include, from, and all the other $VALID_OPTIONs that we have. |
|
I think that we should also put into the readme.md file that the goal of this project is to implement Ruby on Rails version v as faithfully as possible with exceptions a, b, c, d, etc... What is v? I think it's version 4, but am unsure. It depends how far you want to go before releasing this time around. |
Great question. I checked out Rails in the debugger, and it definitely collects multiple select statements, and also supports arrays of field names, so I made the same change, here: aaf8c0d We should probably also support doing variadic lists, like: Book::select("name", "publisher)->take();But let's revisit that kind of thing in a future PR. |
If you're ready to get back to coding, it would be great if you could help out with that effort. I think most of our implementations of these features are a bit undercooked, and I just don't have the energy to go through them all right now. |
|
Implemented |
|
@ipundit Thank you so much for all the great review comments. I know you still have a few ideas about how to do things, but rather than circle around this PR forever I went ahead and merged it so you can resume making your own direct contributions. There are a number of TODO items:
Or whatever you like. Thanks again. |
Description
This is a first pass at aligning more closely with modern Active Record, based on this PR by @ipundit
The broad strokes are that you can now chain relational commands together:
There are a number of major breaking API changes. Briefly:
find_all_by_... -style magic methods have been removed.findno longer takes an options array. The only valid arguments now are primary keys, or arrays of primary keys ("first" and "last" arguments are also no longer supported).count_by_...-style magic methods have been removed.Other changes:
ExpressiontoWhereClauseRelationcan properly return whatever subclass ofModelit is working with. Same forTable.first,last,find) into PHPStan extensions.TODO
Relationneeds to implement iterable, so we can use it withforeachIs that a thing? If it is, I'll need to be careful about how I'm handling "conditions" (internally, I push instances of
WhereClause).