![]() |
DataMapper ORM v1.8.1 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: DataMapper ORM v1.8.1 (/showthread.php?tid=42440) |
DataMapper ORM v1.8.1 - El Forum - 06-25-2011 [eluser]WanWizard[/eluser] The '_id' suffix is indeed hardcoded. As this would be an API change, potentionally breaking existing applications, don't expect it before the next major release. DataMapper ORM v1.8.1 - El Forum - 06-25-2011 [eluser]heldrida[/eluser] Hi WanWizard, I would like to report a bug. If the controller has the same name of model, save() wont be available! For example, CONTROLLERS/menu.php $menu = new Menu(); $menu->name = 'myMenu'; $menu->save(); OUTPUT: ( ! ) Fatal error: Call to undefined method Menu: ![]() MODELS/menu.php Code: class Menu extends DataMapper { After renaming the table to "M" and Model Menu as "M", worked just fine! Keeping the model as "MENU" and the controller "TEST", works fine! I'm using Codeigniter 2.0.2! Still, I have to test in a diferent project, or a clean copy. In the present project, I'm using a MY_CONTROLLER, my controllers are extending MY_CONTROLLER. "TEST" controller above extended MY_CONTROLLER and worked fine! "MENU" controller above extended both CI_CONTROLLER and MY_CONTROLLER, with the reported error. Thanks for looking ![]() DataMapper ORM v1.8.1 - El Forum - 06-25-2011 [eluser]WanWizard[/eluser] That is not a bug, that's a PHP limitation. All your classes must have unique names, PHP doesn't have a concept of models and controllers. This is why all CI classes are prefixed with CI_, and lots of people prefix (or suffix) their model classes. You are getting this error because "new Menu()" will create a new instance of your controller class. Your model isn't even loaded! This could be solved by a specific naming scheme in conjunction with a cascading filesystem autoloader, or by namespaces, like some other frameworks do. But that doesn't work with CI. DataMapper ORM v1.8.1 - El Forum - 06-25-2011 [eluser]heldrida[/eluser] Thanks a lot for letting me know that ![]() DataMapper ORM v1.8.1 - El Forum - 06-27-2011 [eluser]Spelljack[/eluser] Hello WanWizard, Could you please consider adding a model prefix/suffix option to next version or a patch for it? I hacked the DM to use it. I added this to "config/datamapper.php" Code: $config['model_suffix'] = '_model'; Then make some changes in libraries/datamapper.php to replace $config['model_suffix'] with '' where he uses the model name as database name. DataMapper ORM v1.8.1 - El Forum - 06-27-2011 [eluser]WanWizard[/eluser] Could you do me a favor, and fork the Datamapper repo on bitbucket, apply your modifications to the fork, and then send me a pull request? That would save me recreating your solution... DataMapper ORM v1.8.1 - El Forum - 06-27-2011 [eluser]heldrida[/eluser] I'm trying for Adjancency list without success, the following, for the example I gave above: Tbl Category id | name | category_id 1 | catA | 0 2 | catB | 0 3 | catC | 1 4 | catD | 2 5 | catE | 3 class Category extends DataMapper { Code: var $has_many = array( Actually, I've tried diferent ways for doing this. The closest I think was, var $has_many = array( 'category' => array( 'class' => 'category', 'other_field' => 'category' ) ); Where the query gives an error when trying, $catB = new Category(); $catB->where('name','catB')->get(); $catA = new Category(); $catA->where('name','catA')->get(); $catA->save($catB); I can see it tryed to select from "categories_categories". Where $table = "categories"; Can someone give one example based on this table scheme I gave above ? Thanks! [quote author="WanWizard" date="1308958026"]If you're looking to store tree structures, you might want to have a look at the nestedsets extension, included in the Datamapper distribution. See http://datamapper.wanwizard.eu/pages/extensions/nestedsets.html for more information. If you insist on using Adjacency lists: Code: class Mylist extends DataMapper { You'll have to write the methods to navigate through the list yourself, where the nestedsets extension includes all methods to deal with parents, children and siblings...[/quote] DataMapper ORM v1.8.1 - El Forum - 06-27-2011 [eluser]Spelljack[/eluser] [quote author="WanWizard" date="1309189475"]Could you do me a favor, and fork the Datamapper repo on bitbucket, apply your modifications to the fork, and then send me a pull request? That would save me recreating your solution...[/quote] Yea. But it could have some errors. Anyway I will. DataMapper ORM v1.8.1 - El Forum - 06-27-2011 [eluser]Spelljack[/eluser] [quote author="Spelljack" date="1309191835"][quote author="WanWizard" date="1309189475"]Could you do me a favor, and fork the Datamapper repo on bitbucket, apply your modifications to the fork, and then send me a pull request? That would save me recreating your solution...[/quote] Yea. But it could have some errors. Anyway I will.[/quote] I created a fork. Please check it. I could miss some places that add/remove model prefix/suffix on some class calls. I couldn't do a full test. This solution only affects initalizing new instance. other uses are not affected. Eg calling related model: $user->group->get(); I tested it on many to many relationships. DataMapper ORM v1.8.1 - El Forum - 06-27-2011 [eluser]WanWizard[/eluser] @heldrida, If your relation is many-to-many, you will need a relationship table, which in this case is called categories_catergories. If it isn't (which is the case because you use an ITFK), you need to define the parent as has_one (categories can have only one parent categorie), and the children as has_many. If you do that, the relationship table is not used in constructing the queries. |