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

[eluser]Mirage[/eluser]
Thanks again -

Not worried about the performance impact. If anything, I was thinking that column definitions should perhaps be part of the model definition anyway. But it's not that important.

Cheers,
-m

[eluser]ZeusChicago[/eluser]
[quote author="OverZealous" date="1253170734"]@ZeusChicago

First off, I see some (possibly unrelated) problems:

1) There's no reason to manually query the fa_user_id. Instead, use the supported where_related method:
Code:
$subModel->where_related('fa_user', 'id', $this->db_session->userdata('id'));

This is less error prone, and less risky.
[/quote]

note sure what you meant here. I was not querying the fa_user_id field, but mearly setting a where condition to only include records where the fa_user_id was set to the userid of the logged in user

$subscriptionWhere = ('fa_user_id =' .$this->db_session->userdata('id'));
$subModel->where($subscriptionWhere);

So I didnt change this.

[quote author="OverZealous" date="1253170734"]@ZeusChicago
2) join_related is deprecated. Although this won't cause a problem for now, it has been replaced with include_related
[/quote]

Gotcha, I changed to the following

$subModel->include_related('subscriptiontypes','*');

[quote author="OverZealous" date="1253170734"]@ZeusChicago
3) Your SubscriptionType model is incorrect. You always need to describe both sides of the relationship. It must have a $has_many that includes subscription. This is in the troubleshooting guide as things to look for. I have to assume your fa_user model is incorrect, as well.
[/quote]

I have corrected the subscriptiontype model to define both sides of the relationship. You were correct my fa_user model was incorrect as well. This however did not fix the problem either.


[quote author="OverZealous" date="1253170734"]@ZeusChicago
Beyond those problems, I can only assume you have a configuration error in CodeIgniter or DMZ, you are using a class to extend the DataMapper class that is causing conflicts, or something is happening in code outside the code you posted.

Please try the previously recommended hint of seeing what the database is returning, try stripping down your query to fundamental parts (say, just querying for all subscriptions with the given fa_user id), or some other basic debugging.

You also may want to look over the Change Log to see what features might have changed in the past.[/quote]

So I did some additional testing and found this corrected the issue (both the new error I was seeing + only seeing 1 record instead of 2. Either is a configuration issue on my site or a bug in your code. Since I can get around it im happy to move past it at the moment and try to come back later to figure out whats going on, but what I can tell you is this the following
Code:
$subModel->include_related('subscriptiontypes');

returns this error

Code:
A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`) LEFT OUTER JOIN `subscriptiontypes` as subscriptiontypes ON `subscriptiontype' at line 1

SELECT `subscriptions`.*, `subscriptiontypes`.` AS subscriptiontype_ FROM (`subscriptions`) LEFT OUTER JOIN `subscriptiontypes` as subscriptiontypes ON `subscriptiontypes`.`id` = `subscriptions`.`subscriptiontype_id` WHERE `subscriptions`.`fa_user_id` =1 ORDER BY `subscriptions`.`startdatetime` DESC
the query thats being built thats the problem is this part
SELECT `subscriptions`.*, `subscriptiontypes`.` AS subscriptiontype_ FROM

Its missing the * and the closing '

If I however switch it to the following where I specify the fields I want returned, she works, and i might also add the query is now properly returning 2 records as I expected and not 1 Smile

Code:
$subModel->include_related('subscriptiontypes','displayname');

also if I use an array to include a list of fields I want return such as

Code:
$subModel->include_related('subscriptiontypes',array('displayname','name'));

Then the everything works as expected as well. Smile

Finally, if I attempt to pass * such as

Code:
$subModel->include_related('subscriptiontypes','*');

I also get an sql statement that had an error in it which follows. Its similar to the first but not exactly the same
Code:
A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM (`subscriptions`) LEFT OUTER JOIN `subscriptiontypes` as subscriptiontype' at line 1

SELECT `subscriptions`.*, `subscriptiontypes`.* AS subscriptiontype_* FROM (`subscriptions`) LEFT OUTER JOIN `subscriptiontypes` as subscriptiontypes ON `subscriptiontypes`.`id` = `subscriptions`.`subscriptiontype_id` WHERE `subscriptions`.`fa_user_id` =1 ORDER BY `subscriptions`.`startdatetime` DESC

As you can see the issue in the generated query has moved down a bit
SELECT `subscriptions`.*, `subscriptiontypes`.* AS subscriptiontype_* FROM

I am not a sql expert but I am pretty sure you cant alias (with AS) to a fieldname that has a * character in it. So subscriptiontype_* would be an invalid alias.

So in both cases, not passing a field list (which your include_related defaults to NULL) or passing * both produce a SQL query that is not valid.

Thank you for your quick response as they have lead me to a workable solution and in reality its better for me to name the fields I want instead of returning them all any (as im not using them so its just wasting memory return * lol.

Regards

Zeus

p.s. thanks for DMZ, other than today it has made my life much easier Smile

[eluser]OverZealous[/eluser]
[quote author="ZeusChicago" date="1253184551"]
note sure what you meant here. I was not querying the fa_user_id field, but mearly setting a where condition to only include records where the fa_user_id was set to the userid of the logged in user[/quote]
You should still change it to what I was saying. What you did was manually add a where clause that DMZ can handle internally (and safer, as well). I gave an example of the correct way. Basically, if you allow DMZ to handle the query (where clause), it will automatically append the table name correctly, as well as help with protecting the value, etc.

If you really want to avoid the where_related method (and I don't know why you would), at least query it this way:
Code:
$subModel->where('fa_user_id', $this->db_session->userdata('id'));


Also, I'm sorry to admit, but something is definitely broken in DMZ. Now that you helped me narrow it down, I can see this in my example code. Confusedhut:

[eluser]OverZealous[/eluser]
Ah, $#!*! It's a mistake from my last correction. I've got an updated version I'm posting right now.

Edit: Thanks for your patience in tracking this down, Zeus. These kinds of oddball bugs are the most annoying!

DMZ now has so many features that when I make any changes, I seem to break something else entirely!

[eluser]OverZealous[/eluser]
DataMapper OverZealous Edition 1.5.3 Update
Quote:Version 1.5.3:
Recommended for a few minor bugfixes, and one semi-major one with include_related.

Core Changes
• Modified the way _to_object and query processing works, significantly, by merging all query processing code into one new function (_process_query).

Bug Fixes
• Fixed bug that completely broke include_required's ability to automatically add all fields.
• Fixed bugs with get_rules not being called correctly for related queries and validate->get() queries.
• Invalid relationship queries now show an error instead of silently failing.
• Fixed typo in Troubleshooting where the word 'related' was supposed to be 'required'.
Quote:Download the Latest Version Here

View the change log and the upgrade process
Having issues? Please look through the Troubleshooting Guide & FAQs
View the Complete Manual

[eluser]emorling[/eluser]
Thanks for the upgrade!

I have an issue which I don't know if it's related to DMZ or CI in general.

This controller function is sometimes called twice, and I have no clue what causes it?

Code:
function sell($char_id, $item_id){
        // get character and item
        $char = new Character(); $char->get_by_id($char_id);
        $item = new Item(); $item->get_by_id($item_id);
        // payout 10 gold to character
        $char->add_gold(10);        
        // save character and delete item
        $char->save();
        $item->delete();
        redirect('/ui/shop/'.$char->id);        
}

I can add this to avoid the function being called twice, but I still don't understand why it doesn't work...

Quote:if(!$item->exists()){redirect('/ui/shop/'.$char->id);}

Any help appreciated.

EDIT: Reason I know it's called twice is that it pays out 20 instead of 10.

[eluser]emorling[/eluser]
It seems the $item->delete() is causing the controller function to be called again, is this possible? E.g. is there an exception which will cause the controller to retry?

[eluser]OverZealous[/eluser]
[quote author="emorling" date="1253203185"]It seems the $item->delete() is causing the controller function to be called again, is this possible? E.g. is there an exception which will cause the controller to retry?[/quote]

I don't know if you still need the information, but there is nothing I know of that can cause CI to reload the same function, EXCEPT if you are accidentally calling $this->{controller_method}.

Meaning, something like this:
Code:
function delete($id) {
    $object = new Object();
    $object->get_by_id($id);
    if($object->exists()) {
        $this->delete();
//      ^^^^^--{ wrong object reference }
    }
}

That would call the controller method a second time. And because it isn't getting the $id the second time, it won't fall into a recursive loop.

DMZ itself would never have any reason to be able to call a controller method, unless you passed a controller ($this) into a DMZ method, and even then it is unlikely.

[eluser]Daniel H[/eluser]
Hi Phil -

I wonder if you saw this issue I had with the array extension?

http://ellislab.com/forums/viewthread/11...20/#637196

[eluser]Daniel H[/eluser]
Is it at all possible to load all an object's related 'has one' objects on an ad hoc basis, instead of specifying it in the config?




Theme © iAndrew 2016 - Forum software by © MyBB