Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.1
#71

[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.
#72

[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:Confusedave()

MODELS/menu.php
Code:
class Menu extends DataMapper {

   var $table = 'menus';

    
    // Optionally, don't include a constructor if you don't need one.
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
    
    // Optionally, you can add post model initialisation code
    function post_model_init($from_cache = FALSE)
    {
    }
    
}

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 Wink
#73

[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.
#74

[eluser]heldrida[/eluser]
Thanks a lot for letting me know that Wink
#75

[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.
#76

[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...
#77

[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(
        'parent' => array(
            'class' => 'category',
            'other_field' => 'category'
        ),
        'category' => array(
            'other_field' => 'parent'
        )
);


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/ext...dsets.html for more information.

If you insist on using Adjacency lists:
Code:
class Mylist extends DataMapper {
    $has_many = array(
        'parent' => array(
            'class' => 'mylist',
            'other_field' => 'mylist',
        ),
        'mylist' => array(
            'other_field' => 'parent',
        )
    );
}

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]
#78

[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.
#79

[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.
#80

[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.




Theme © iAndrew 2016 - Forum software by © MyBB