CodeIgniter Forums
DataMapper ORM v1.8.2 - 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: DataMapper ORM v1.8.2 (/showthread.php?tid=47243)



DataMapper ORM v1.8.2 - El Forum - 07-23-2012

[eluser]Netstrike[/eluser]
Hi, it's possible to load a datamapper model into a library?
How can i do?

Tnx
Ettore


DataMapper ORM v1.8.2 - El Forum - 07-23-2012

[eluser]WanWizard[/eluser]
Datamapper comes with it's own autoloader, so this will work anywhere:
Code:
// load a datamapper model
$model = new Modelname();



DataMapper ORM v1.8.2 - El Forum - 07-23-2012

[eluser]Netstrike[/eluser]
I have tried it, but the result is (in the error log of apache):

PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 65488 bytes) in C:\\Users\\netstrike\\Desktop\\UniServer\\www\\Project\\application\\third_party\\datamapper\\bootstrap.php on line 358, referer: http://localhost/

... the 358 line in the bootstrap file doesn't exist... the bootstrap have only 91 lines...

The library enter in loop ad reload itself...



DataMapper ORM v1.8.2 - El Forum - 07-24-2012

[eluser]WanWizard[/eluser]
Time to do some debugging then...


DataMapper ORM v1.8.2 - El Forum - 07-24-2012

[eluser]Netstrike[/eluser]
I have find the problem...
I tried to instantiate the model into __construct() of library...
Now, i Instantius the model in a method of library and it work fine.


DataMapper ORM v1.8.2 - El Forum - 07-24-2012

[eluser]WanWizard[/eluser]
It shouldn't be an issue to instantiate objects in a constructor.

Unless you model uses that library in it's constructor. When you do that the library isn't marked 'loaded' yet by CI's singleton system, so a load in the model constructor will trigger another attempt by CI to load the library...

If that is not the case, I can't see why it would introduce a loop. Have you checked the backtrace to see what is calling what?


DataMapper ORM v1.8.2 - El Forum - 07-25-2012

[eluser]Andre83[/eluser]
Hi everyone,

a quick question about data validation using DataMapper v.1.8.2. I've created a model and saved some records, not setting any validation rules. I've then introduced a 'required' validation on one of the model's fields.

Validation works fine when trying to add new records to the database, but fails when editing previously saved data.

E.g.

Code:
$activity = new Activity();
$activity->where('id', $id)->get();

$activity->activity_note = '';
$activity->save();

In this case, being 'activity_note' the required field, $activity-save() should return FALSE, instead it does return TRUE.

By the way, this is how I've defined the validation rule inside the Activity model:

Code:
var $validation = array(
  'activity_note' => array(
   'label' => 'Activity note',
   'rules' => array('required')
  )
);

I'd be glad if you could give me any input on this, as I'm kinda stuck Smile


DataMapper ORM v1.8.2 - El Forum - 07-25-2012

[eluser]WanWizard[/eluser]
Data in the database is considered correct. If you can't take that assumption, you have a big data integrity issue Wink.
When updating an object, it will only validate changed properties.

So if you introduce rules afterwards that will invalidate your data, run some code that will correct your data so it's integer again.

Migrations are the best option for that, you don't solve that with validation, as long as you don't retrieve your data, it will stay incorrect in your table, and can impact code that relies on that data ( I assume you don't put the validation rules in there for a reason).


DataMapper ORM v1.8.2 - El Forum - 07-25-2012

[eluser]Andre83[/eluser]
Thanks for your reply, it makes totally sense Smile

In case one wanted to always validate data upon save, I've found out that we can always use something like:

Code:
$object->force_validation()->save()

but, as you said, data stored in the database MUST be correct in the first place.

Thanks!


DataMapper ORM v1.8.2 - El Forum - 07-25-2012

[eluser]Jacob F.[/eluser]
So I'm doing an include_related followed by an or_ilike, and it seems that they cannot be used together.
Code:
$o
->include_related('user',array('name'),TRUE)
->include_related('user/group',array('name'),TRUE)
->where_related('user/group','id',$id)
->or_ilike($col,$search) //only on subsequent queries
->get_paged($current_page,$display_count);

The first query that happens (no or_ilike) has a select like this:
Code:
SELECT `o`.*,
`user`.`name` AS user_name,
`user_group`.`name` AS user_group_name,
FROM (`o`)
  LEFT OUTER JOIN ...

But subsequent queries (triggered via AJAX) have a completely different select that seems to half ignore the include_relateds
Code:
SELECT COUNT(*) AS `numrows`
FROM (`o`)
  LEFT OUTER JOIN ...

The SQL of subsequent queries after the FROM is as I expect, however, the missing pieces in the primary select that are referenced in the JOINS (which are the same in both queries) breaks because user_group_name was not defined.