Skip to content
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

Simple way to make working with Paris more beautiful? #62

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ foreach ($tweets as $tweet) {
}
```

Users who have PHP 5.3+ can simply do the following:
```php
$user = User::where_equal('username', 'j4mie')
->find_one();
```
instead of:
```php
$user = Model::factory('User')
->where_equal('username', 'j4mie')
->find_one();
```

Changelog
---------

Expand Down
14 changes: 13 additions & 1 deletion docs/querying.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ record by its primary key ID:
<?php
$user = Model::factory('User')->find_one($id);

If you are using PHP 5.3+ you can also do the following:

.. code-block:: php

<?php
$users = User::where('name', 'Fred')
->where_gte('age', 20)
->find_many();

This does the same as the example above but is shorter and more readable.


The only differences between using Idiorm and using Paris for querying
are as follows:

Expand Down Expand Up @@ -150,4 +162,4 @@ be returned.
// Returns array('first_name' => 'Fred', 'age' => 50)
$data = $person->as_array('first_name', 'age');

.. _Idiorm: http://github.com/j4mie/idiorm/
.. _Idiorm: http://github.com/j4mie/idiorm/
13 changes: 13 additions & 0 deletions paris.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,17 @@ public function id() {
public function hydrate($data) {
$this->orm->hydrate($data)->force_all_dirty();
}

/**
* Calls static methods directly on the ORMWrapper
*
*/
public static function __callStatic($method, $parameters)
{
if(function_exists('get_called_class')) {
$model = self::factory(get_called_class());

return call_user_func_array(array($model, $method), $parameters);
}
}
}
8 changes: 7 additions & 1 deletion test/ParisTest53.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ public function testModelWithCustomTable() {
$expected = 'SELECT * FROM `custom_table`';
$this->assertEquals($expected, ORM::get_last_query());
}

public function testShortcut() {
\Paris\Tests\Simple::find_many();
$expected = 'SELECT * FROM `paris_tests_simple`';
$this->assertEquals($expected, ORM::get_last_query());
}

}

class Simple extends Model { }
class ModelWithCustomTable extends Model {
public static $_table = 'custom_table';
}
}