Closed michaelward82 closed 10 years ago
You want to use the factory for all access.
You can alias on the model like so if you wish:
class User extends Model {
public static function one($id) {
return Model::factory(__CLASS__)
->find_one($id);
}
}
$user = User::one(20);
I think I will opt for manually specifying the table name in the model.
The way namespace are handled, is it the intended behaviour for Paris? I believe the static methods could work using the short name for the class, which I believe can be determined.
I'm not suggesting that is what Paris should do, but it is something it could do.
Thoughts?
Well I didn't add namespace support so I am not sure what the intention of that patch was. If it could be achieved without losing PHP 5.2 support then that would be great. I haven't really looked myself so I can't tell you I am afraid.
Ok, I'll investigate.
The behaviour is expected and documented.
From paris.php
, line 204:
/**
* Convert a namespace to the standard PEAR underscore format.
*
* Then convert a class name in CapWords to a table name in
* lowercase_with_underscores.
*
* Finally strip doubled up underscores
*
* For example, CarTyre would be converted to car_tyre. And
* Project\Models\CarTyre would be project_models_car_tyre.
*/
protected static function _class_name_to_table_name($class_name) {
...
Given the existing documentation and the need for backward compatibility, any changes to behaviour here would probably require an option to switch it on.
Given that the only configuration I can see is in the Idiorm ORM class, I'm not sure how we would want to set such an option given that it's nothing that Idiorm is concerned with.
Maybe a property of Model
- which could be set individually, or using inheritance?
Lets image I have a model of class
User
. I have a namespace to theUser
class, which isvendor\model
. My table name isuser
.Using the factory method, everything works as expected:
However, using the static methods I get an error indicating that Paris is looking for the table
vendor_model_user
.I can avoid this problem if I manually specify the table name. This is something I can do, but I don't want to take unneeded manual steps.
So two questions: