CodeIgniter Forums
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - 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: [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) (/showthread.php?tid=18196)



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-12-2009

[eluser]sethbaur[/eluser]
You were right, it was a config issue Smile. Thanks.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-12-2009

[eluser]OverZealous[/eluser]
@mcnux

Try just using select on it's own, for unusual methods:

Code:
$myTable->select('month')->select('COUNT(myInt) myCount')->group_by('month');

(Note: I don't use MySQL, so you might need to protect the identifiers with ` in that statement.)

I've been toying with the idea of creating something like select_function($function, $args), and maybe a more generic *_function($fname, $args, ...) (where * is where, like, etc). But there needs to be some work on the idea yet, like how to distinguish between string args and column names.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]mcnux[/eluser]
[quote author="OverZealous" date="1250114667"]@mcnux

Try just using select on it's own, for unusual methods:

Code:
$myTable->select('month')->select('COUNT(myInt) myCount')->group_by('month');

(Note: I don't use MySQL, so you might need to protect the identifiers with ` in that statement.)

I've been toying with the idea of creating something like select_function($function, $args), and maybe a more generic *_function($fname, $args, ...) (where * is where, like, etc). But there needs to be some work on the idea yet, like how to distinguish between string args and column names.[/quote]
Understood. It would be nice to have these methods available as more and more SQL is creeping into my app but appreciate this is a tricky one. TBH, the only function I'm really missing at the moment is count - I might just add select_count() to my extension for the time being.

Ta


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]mcnux[/eluser]
Me again!

Is there any reason why relationships aren't deleted before the object to be deleted is deleted? The benefit would be that foreign key constraints would no longer fail and, I think, it makes more sense to remove relationships before deleting, doesn't it?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]OverZealous[/eluser]
[quote author="mcnux" date="1250175064"]Is there any reason why relationships aren't deleted before the object to be deleted is deleted? The benefit would be that foreign key constraints would no longer fail and, I think, it makes more sense to remove relationships before deleting, doesn't it?[/quote]

Well, I'd like to hear other's opinion on this, because somewhat I agree with you. (A lot of this code is not mine, so I don't always have the reasoning behind something.)

The only good reason I can see is that deleting the object first allows the Database to handle cascades, which should be significantly faster and safer (transactionally speaking).

If you have foreign constraints, you really should have deletion rules set up to cascade properly. This would prevent those errors. Since DMZ doesn't actually delete any related objects automatically, you still need to determine the correct order to delete objects in.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]mcnux[/eluser]
[quote author="OverZealous" date="1250183131"]
Well, I'd like to hear other's opinion on this, because somewhat I agree with you. (A lot of this code is not mine, so I don't always have the reasoning behind something.)
[/quote]
Yes understood. Maybe this could be configurable?

[quote author="OverZealous" date="1250183131"]
The only good reason I can see is that deleting the object first allows the Database to handle cascades, which should be significantly faster and safer (transactionally speaking).

If you have foreign constraints, you really should have deletion rules set up to cascade properly. This would prevent those errors. Since DMZ doesn't actually delete any related objects automatically, you still need to determine the correct order to delete objects in.[/quote]
I'm reluctant to let the database handle the cascade as it splits the responsibility of relationship cleanup between the application and the database. I would rather give the responsibility wholly to either the application or the database, otherwise it becomes a little unclear what's doing what.

I still like to have constraints in place within the schema purely to ensure that the database remains in tact, no matter what the application attempts to do.

However, maybe I should be shifting the responsibility to the database. I'll certainly have a think about it.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]leviathan28[/eluser]
First: I just love DMZ ^^ thanks for this great tool

Now I've got a little problem concerning limiting results.

This code

Code:
$state = new State();
$state->get_by_id(State::STATE_NEW);
$state->import->limit(1);
$state->import->get();

results in that

Code:
SELECT `imports`.*
FROM (`imports`)
LEFT OUTER JOIN `imports_states` as imports_states ON `imports`.`id` = `imports_states`.`import_id`
LEFT OUTER JOIN `states` as states ON `states`.`id` = `imports_states`.`state_id`
WHERE `states`.`id` = '1'

There should be a "LIMIT 1" somewhere, shouldn't it?
Or am I missing something?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]mcnux[/eluser]
[quote author="leviathan28" date="1250189978"]First: I just love DMZ ^^ thanks for this great tool

Now I've got a little problem concerning limiting results.

This code

Code:
$state = new State();
$state->get_by_id(State::STATE_NEW);
$state->import->limit(1);
$state->import->get();

results in that

Code:
SELECT `imports`.*
FROM (`imports`)
LEFT OUTER JOIN `imports_states` as imports_states ON `imports`.`id` = `imports_states`.`import_id`
LEFT OUTER JOIN `states` as states ON `states`.`id` = `imports_states`.`state_id`
WHERE `states`.`id` = '1'

There should be a "LIMIT 1" somewhere, shouldn't it?
Or am I missing something?[/quote]
I imagine Phil will come back with an explanation as to why the limit has not been added using your method but have you tried $state->import->limit(1)->get()?

EDIT: The user guide also indicates that $state->import->get(1) should work. First parameter being the limit. See http://www.overzealous.com/dmz/pages/get.html.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-13-2009

[eluser]OverZealous[/eluser]
[quote author="leviathan28" date="1250189978"]There should be a "LIMIT 1" somewhere, shouldn't it?
Or am I missing something?[/quote]

Yes, there should be a limit. DMZ relies on CodeIgniter's ActiveRecord, so there is no reason why that shouldn't work.

Is the code you've copied in exactly what you are running? Or have you made changes to it?

If you haven't made any changes, can you try this, to help debug it?
Code:
$import = $state->import;
$import->limit(1);
$import->get();



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 08-14-2009

[eluser]leviathan28[/eluser]
$state->import->limit(1)->get() didn't work either but $state->import->get(1) did - thanks Smile

Quote:Is the code you’ve copied in exactly what you are running? Or have you made changes to it?

Yes, 100%. Runs from a library, though. I don't know if that makes any difference.


Quote:If you haven’t made any changes, can you try this, to help debug it?
Code:
$import = $state->import;
$import->limit(1);
$import->get();

I tried and there is still no "limit 1".