CodeIgniter Forums
DataMapper ORM v1.8.0 - 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.0 (/showthread.php?tid=37531)



DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]introvert[/eluser]
Hey,

I havent touched field_label_lang_format configuration, so I have no idea why is the empty string coming up.


DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]WanWizard[/eluser]
Well, that makes two of us... Wink

Try do add some custom logging to your controller, to determine with Datamapper method causes the log entry. Then debug that Datamapper method to see what causes it. I can't reproduce it here in my test environment.


DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]introvert[/eluser]
Hey,

I put a backtrace on Lang line() function:

Heres what I get:

Code:
#0  CI_Lang->line(site_redirect) called at [/Applications/MAMP/htdocs/app/application/libraries/datamapper.php:5800]
#1  DataMapper->localize_by_model(${model}_${field}, redirect) called at [/Applications/MAMP/htdocs/app/application/libraries/datamapper.php:5818]
#2  DataMapper->localize_label(redirect) called at [/Applications/MAMP/htdocs/app/application/libraries/datamapper.php:5991]
#3  DataMapper->_relationship(has_many, redirect, 0) called at [/Applications/MAMP/htdocs/app/application/libraries/datamapper.php:644]
#4  DataMapper->DataMapper() called at [/Applications/MAMP/htdocs/app/application/libraries/datamapper.php:428]
#5  DataMapper->__construct() called at [/Applications/MAMP/htdocs/app/application/models/site.php:9]
#6  Site->__construct() called at [/Applications/MAMP/htdocs/app/application/models/site.php:28]
#7  Site::get_current() called at [/Applications/MAMP/htdocs/app/application/core/Public_Controller.php:27]
#8  Public_Controller->_init() called at [/Applications/MAMP/htdocs/app/application/core/Public_Controller.php:17]
#9  Public_Controller->__construct() called at [/Applications/MAMP/htdocs/app/application/controllers/front.php:10]
#10 Front->__construct() called at [/Applications/MAMP/htdocs/app/system/core/CodeIgniter.php:288]
#11 require_once(/Applications/MAMP/htdocs/app/system/core/CodeIgniter.php) called at [/Applications/MAMP/htdocs/app/public/index.php:201]

It appears that when Datamapper object is initialized, it calls localize_by_label, which I have no idea why is it called.

Does it make any sense to you?

Thanks for help


DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]WanWizard[/eluser]
That what I said:

If you define a custom validation rule, the field (or column) name can be included in the error message, and can be localized. For example, this is needed if you define an error on the field 'username'. In a german error message, you would like to use 'Benutzername' instead.

So localize_by_label() checks if a translation exists, and the only way to do that is to call $this->lang->line(), and check the result.

I already filed a 'complaint' in the reactor issue (#32) that introduced this new and imho extremely unwanted behaviour, but so far no positive reaction of the Reactor team.


DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]introvert[/eluser]
Do you have any idea why the empty line is being passed to the line function?


DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]WanWizard[/eluser]
No, that's why I said some debugging is needed. I can't reproduce it here, so I'm afraid that's up to you.


DataMapper ORM v1.8.0 - El Forum - 05-13-2011

[eluser]introvert[/eluser]
Ok,

I figured out that each logged error goes away if I define every column in model $validation rules.
I'm not sure if this is a fix for my problem: is this normal - expected behavior or should I look somewhere else?

The new CI behavior to log each such lang() event as an error is really retarded, and I hope they change this soon.

Another thing:
where I have $has_one relations in my model, I have to define the column as 'column_id' (with trailing id), where $has_many relation could be defined just with 'column'.

For instance $has_many has to be:
Code:
var $has_many = array('Site');
var $validation = array('site' => array('label' => 'Site'));

in has_one case, for the error to go away:
Code:
var $has_one = array('Site');
var $validation = array('site_id' => array('label' => 'Site'));

Is this normal?
It would make more logic to have 'site' in both cases, since the Model knows that its in relation with Site model.

Thanks for help


DataMapper ORM v1.8.0 - El Forum - 05-14-2011

[eluser]Unknown[/eluser]
hi
I would like to ask , if I can specify and ID field name , rather than the the "id" default ?

means , I got a table who's primary key is "serial" not "id"

any idea ?


DataMapper ORM v1.8.0 - El Forum - 05-14-2011

[eluser]WanWizard[/eluser]
@Nedal Salah,

No, at the moment you are required to use 'id'.

Datamapper follows the design principe that 'id' should be the primary key, integer, and auto_increment. An abstract value, with no meaning within your application. This means you have full freedom to work with your table data without having to deal with major database changes (ever tried to redesign the database where application values are used as foreign keys. A nightmare).


DataMapper ORM v1.8.0 - El Forum - 05-14-2011

[eluser]WanWizard[/eluser]
@introvert,

As to the 'id' suffix question, see my answer in the previous post. There is a feature request for alternative 'id' naming, but it is not on the roadmap for the moment.

As for the lang() error, Datamapper automatically creates a validation rule for the 'id' field, to make sure it's present, defined as integer, and has a proper value. Could be that is causing the issue, but strange I don't see it in my logs here. I'll do some more testing.