-
Notifications
You must be signed in to change notification settings - Fork 440
[WIP] 1.1 Updates #430
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
base: master
Are you sure you want to change the base?
[WIP] 1.1 Updates #430
Conversation
The logic in the Model::__set() magic method allowed for either an aliased attribute *or* a custom setter, but not both. If a custom setter method was defined for an aliased attribute, then the attribute value would be set without going through the custom setter method. Changed the logic so that the _set() method first normalizes an aliased attribute into the real attribute name, then checks to see if an there is a custom setter method defined and runs it if it exists.
This is really awesome work, @koenpunt. Thanks! |
975878c
to
6309d9e
Compare
Something missing from this is a giant upgrade to the documentation :(. |
Where is the source of the documentation located? |
Added documentation to-do to the description |
Hilariously, it is on a private Redmine-based repo. That could be dropped for a static site since we don't need the forums and everything else we have on |
What about setting it up on readthedocs.org? |
@cvanschalkwijk thanks for the merge, but that's a lot of noise for a single commit.. |
Oh I see what happened. I rebase this branch on master once in a while, and you merged master into it. |
The default PHP boolean-to-string casting does not work for some database connection types (e.g. PostgreSQL). Added a BOOLEAN type to the Column class, and then the cast() method delegates to the a new boolean_to_string() method in the Connection class. By default the boolean_to_string() method returns the standard PHP string cast for the boolean, retaining the original behavior. This method can be overridden in adapter classes to provides custom casting of boolean values. Added an overridden boolean_to_string() method into the adapters/PgsqlAdapter.php class which casts the boolean values false and true to the strings "0" and "1" respectively. These string values are then recognized by the Postgres database as boolean values, as opposed to the values "" and "1" generated by the standard PHP cast.
Updated the ColumnTest::assert_cast() to test that boolean values are being casted using the Connection boolean_to_string() method. Added a PostgreSQL specific test to ensure that boolean values are being casted as the correct string value.
Modified the boolean_to_string() method in the PgsqlAdapter class to properly convert values that PHP considers a boolean, as well as what PostgreSQL considers a boolean value. E.g., PostgreSQL considers the values 'f', 'false', 'n', 'no', and 'off' as valid values for `false`, but PHP does not. The original implementation of this method would return `true` for one of these values which is incorrect for a PostgreSQL database. Also modified the base Connection class boolean_to_string() method to first cast its `$value` parameter as a boolean before casting it to a string. This will account for PHP's loose type-casting and make sure the method returns a consistent casted value.
While the previous version was explicit and descriptive, it wasn't that elegant. This is much nicer.
Protect mass assignment by filtering input data using StrongParameters $user_params = new ActiveRecord\StrongParameters($_POST['user']); $user_params->permit('name', 'bio'); $user = new User($user_params); $user->save();
parse_str is about 60% faster than custom parsing using foreach loop
sscanf is about 40% faster than using a regex
code formatting
fetching values is now also possible using ArrayAccess. So instead of $params->fetch('name') You can now also do: $params['name'];
add missing tables to pgsql fixture add password to users table make test more readable
Feature: StrongParameters
Cache validation result.
Include @suxxes changes
relationship references wrong table
separate connection string parsing from connection
Issues to process
Clean merge of fixed mysql datetime handling #440 (Better Datetime handling #317) -- cast to DateTime via connection(invalid issue)Other
SnakeCase_PHPUnit_Framework_TestCase
assert_equals/true/false
calls toassertEquals/True/False
etc.Documentation
(I believe the documentation is already there, only the implementation was missing)
Optional
See the changes of this PR with
?w=1
to ignore whitespace changesComments regarding 1.1 should be added to #357