Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]bEz[/eluser]
Yes....Sir!!!! Smile

Providing a paired code and documented solution should suffice most of the novice users of CI, and will allow more time for you to concentrate on the next round of expansions and updates.
I will give the docs a good "re"-read for anything that may be too technical or is not read in laymen's terms. I think that was the main reason for the repeated questions. I dont think a sub-forum was the key at all.

p.s. - I had a good feeling that you would have gone with the "include_related" alternate function. Tongue

-bEz

[eluser]naren_nag[/eluser]
Phil,

Superfantabuloustic!

It's documentation of this quality that separates the men (or women) from the boys (or girls) :/

cheers

[eluser]warrennz[/eluser]
Heya guys


Just got a small issue - thought I would post it before I go ripping datamapper apart in case someone can quickly shed some light on my errors..


I have users in a M:M relationship with privileges


I can do this,

Code:
$u = new User();
$u->get_by_id(99);

$p = $u->privileges->get(); // ->all contains all the correct privileges as expected

but I cannot do this

Code:
$p = new Privileges();
$p->get_by_name('staff');

$u = $p->user->get(); //Doesn't query the DB,

The relation is pretty straight forward, user table with id, privileges table with id, privileges_users table with user_id and privilege_id. The fact it works one way is kinda saying the data setup is correct, I've done a little debugging and get_by_name() is definitely getting a privilege with an id that is present in the relationship table.


Any quick thoughts?

Thanks

[eluser]NachoF[/eluser]
Quote:"privileges_users table with user_id and privilege_id"
it also needs an id field.

[eluser]warrennz[/eluser]
@NachoF

Yes sorry it does have an ID field too. Sad

[eluser]OverZealous[/eluser]
DMZ Updated!

Quote:Version 1.3.0: This update brings two big new features.

Extensions: You can now easily create extensions that you can share with others. They are incredibly easy to create, and can be loaded only when needed.

Learn more about extensions.

Production Cache: This configuration option allows DataMapper to cache the database schema so it doesn't have to be loaded with every page request. It also caches some other minor setup information.

Learn more about the production cache.

Please download [url="http://www.overzealous.com/dmz/DMZ_1.3.0.zip"]version 1.3.0 here[/url].

[eluser]OverZealous[/eluser]
@warrennz
Check out Why does my relationship work from one object, but fail from the other? in the troubleshooting guide.

Most likely there is something missing or incorrectly typed on the Priviledges class.

Oh, yeah, I forgot to mention that DMZ now has a fairly in-depth set of FAQs!

[eluser]warrennz[/eluser]
OK!

I found what was causing the issue I'm just unsure of what to do next Smile

I had a look at the parsed has_many() relationships array in the privileges model.

Quote: [user] => Array
(
[class] => user
[other_field] => privilege
[join_self_as] => privilege
[join_other_as] => user
)

The model is terribly basic,
Code:
class Privileges extends DataMapper {

    var $has_many = array("user");

    function Privileges()
    {
        parent::DataMapper();
    }
}


And again this is the relationship from the user model

Quote: [privileges] => Array
(
[class] => privileges
[other_field] => user
[join_self_as] => user
[join_other_as] => privileges
)

from

Code:
class User extends DataMapper {

    var $has_many = array("history","group","privileges");

    function User()
    {
        parent::DataMapper();
    }
}


So, privileges has become privilege. To test this I renamed all cases of the plural (filename, class name, method, references to privileges in other models) to a singular and it works fine now.

So yea, any ideas on that one?


I could define that rest of that relationship for example

privileges model
var $has_many = array("user" => array('class' => 'user', 'other_field' => 'privileges'));

But that of course means the relationship table needs privileges_id instead of privilege_id

@OverZelous
Does that FAQ still apply? I read it but not 100% sure.

Thanks

[eluser]OverZealous[/eluser]
@warrennz

Basically, you have mis-named your Privileges class. If you read through the docs, you'll see that the model should always be named singularly, ie: Privilege.

However, there is a solution that will work most of the time: Hard code your model name into Privileges like this:
Code:
class Privileges extends DataMapper {
    var $model = 'privileges';
    ...

I recommend changing the name of the class, if you can, because there are a few other places in DataMapper that might eventually give you trouble down the road.

[eluser]Matthew Lanham[/eluser]
@OverZealous.com

Good work on the new version, and i am so happy you have merged your documentation and download etc that was getting to be a pain in the ass going to 2 different websites, so thanks for that!!!!




Theme © iAndrew 2016 - Forum software by © MyBB