Welcome Guest, Not a member yet? Register   Sign In
recommendations on ORM vs custom data mapper
#1

[eluser]Chillahan[/eluser]
I am having trouble deducing what ORM (if any) to use. IgnitedRecord is old now and I can't tell that it's actively supported. Is Doctrine or Propel the only choice? I assume I'd still need to integrate them manually into CI, loading their objects from my models.

Or do I need any ORM?

Here's what I want to achieve:

- true active record objects, where I can load an object that is more complex than just one table's worth of data;
- use of objects throughout business logic (library, controllers) and views, instead of arrays;

I am stuck on deciding whether to roll my own in my business logic library (I assume if I return a collection of objects it will just pass through to the view and can be iterated through as such), or to use an ORM to help generate the basic classes, which I can extend to create my custom business objects, with the associations and data rules inherent to them.

Suggestions? Thoughts?
#2

[eluser]toopay[/eluser]
Sprig, Kohana stuff.
#3

[eluser]cahva[/eluser]
To answer to the question if there are other options, there is DataMapper ORM which I've used couple of times in my projects and can recommend it. Test it out to see if it fits to your project(s).
#4

[eluser]Chillahan[/eluser]
[quote author="toopay" date="1304939513"]Sprig, Kohana stuff.[/quote]

??? I am not using Kohana on this project, just refactoring code in CI.
#5

[eluser]Chillahan[/eluser]
[quote author="cahva" date="1304951584"]To answer to the question if there are other options, there is DataMapper ORM which I've used couple of times in my projects and can recommend it. Test it out to see if it fits to your project(s).[/quote]

I looked at DataMapper but it seemed discontinued - I did find a release date from January of this year in the link you sent, so I guess I was unsuccessful in finding the updated version!

How does DataMapper compare to Doctrine? To me it seems Doctrine is more well-established, more likely to stay alive - is the downside that Doctrine is slower/heavier/cumbersome to use? What about Doctrine 2.0 (I have yet to research that option)?

And what about my original question - how do I best encapsulate business functionality? Is it by using an ORM and overloading the default get/set methods, or using a custom library (and within that, either using regular CI database model or use ORM within)?

Here's an example - let's say I have a set of classes on offer. Before I can publish the next tutorial in a class, I need to make sure no one has not passed the previous class, with a pass being an average number of correct answers on a quiz for that class. But if someone didn't take the quiz and the deadline is past, their failing score should not keep the class back. Likewise, if someone fails twice in a row, they should not hold the class back.

Here are different approaches I see (with pseudo-code):

I. script-style - controller handles business logic of performing all these checks, by using simple method calls for the class in question:

if count_failed_grades($classID) == '0' (and inside that query handle a sub query for expired deadlines)

II. object style, using library with regular CI model -

$myClass = new Class($classID)
if $myClass.countFailedGrades == '0' (and inside class, same logic as above)

III. object style, using library with custom data mapper or ORM -

$myClass = new Class($classID)
if $myClass.countFailedGrades == '0'
...inside library class...
constructor($classID):
$this.grades = $ORM->grades->retrieveAllbyClassID($classID);
function countFailedGrades()
... iterate through grades object collection ...


Thoughts?
#6

[eluser]WanWizard[/eluser]
[quote author="Chillahan" date="1304981137"]I looked at DataMapper but it seemed discontinued - I did find a release date from January of this year in the link you sent, so I guess I was unsuccessful in finding the updated version![/quote]
Don't know where you looked (but I'd like to know), but Datamapper is indeed far from dead!

I can't comment on other solutions, but with Datamapper, the ORM models replace the standard CI models.
Datamapper provides them with a lot of functionality to make relations and CRUD operations. You simply add the methods needed by your business logic.

As per your example:
Code:
// get all classes by id
$myClass = new Class();
$myClass->get();

// create a class object for class $classID
$myClass = new Class($classID);

// for this class, get all grades below a value
$myClass->grades->where('grade <', $grade)->get();

// some complicated calculations in a custom model method called getgrades()
$myClass->getgrades();
#7

[eluser]Chillahan[/eluser]
I think I saw an older message thread for it that ended in 09. I see your updated thread now!

Any thoughts on my planning though for putting logic into Library with or without use of ORM?
#8

[eluser]WanWizard[/eluser]
Basically, for every new release a new thread is created.

With Datamapper, there are no libraries involved. All data related logic sits in the model.
#9

[eluser]Chillahan[/eluser]
So you're saying, from my example, that the relations between test scores, deadlines, and the classes would be set up as a database relation, and any rule checking (average score against deadline and number of attempts) could be handled by adding custom methods to the DataMapper ORM auto-generated classes? (and thus no need to add my own custom objects via a library?)

Also, is there a good resource for pros/cons of DataMapper vs doctrine? I am assuming since it was built for CI it is easier to use from a CI developer's perspective? (I can search more myself for a comparison, just wondering if you had any hints since it's your project now!)

Also does DataMapper work alongside Modular CI nicely? I've been looking at Matchbox, etc., since I am also thinking of incorporporating the HMVC pattern in this refactoring that I am doing. You might be my one stop shop! Smile
#10

[eluser]Chillahan[/eluser]
Also, I completely missed your response to my pseudo-code, as I read it in my e-mail and didn't see that part! So you already answered most of my question above. Thank you for that response sample pseudo-code!




Theme © iAndrew 2016 - Forum software by © MyBB