Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]Procode[/eluser]
Hello, I am trying to use datamapper with cibonfire in a module that I have created, but I am having a problem passing the generated data to the view.

The problem is that when I do this...

Controller:

Code:
$link = new Link();
$records = $link->get_iterated();

Template::set('records', $records);
Template::set('toolbar_title', 'Manage LinkLogik');
Template::render();

View:

Code:
foreach($records as $r):
    echo $r->field_name;
endforeach;


The error I see is:

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 'EXPLAIN SELECT * FROM (`lgk_settings`)' at line 1

EXPLAIN EXPLAIN SELECT * FROM (`lgk_settings`)

Filename: /Applications/XAMPP/xamppfiles/htdocs/project_dir/libraries/Profiler.php

Line Number: 197

However if I use the array extension and convert it to an array $link->all_to_array() it works fine, however Im wondering if I can directly use the object in my view?

Thank you.

[eluser]WanWizard[/eluser]
Datamapper doesn't inject EXPLAIN into the SQL (and certainly not twice), so I haven't got a clue where this comes from.

[eluser]Procode[/eluser]
[quote author="WanWizard" date="1370240499"]Datamapper doesn't inject EXPLAIN into the SQL (and certainly not twice), so I haven't got a clue where this comes from.[/quote]

Yea, the interesting part is the Parser.php file, doesn't even exist at the path that the error specifies, which makes it even more weird. Have you ever used datamapper with cibonfire?

[eluser]WanWizard[/eluser]
I don't even know what cibonfire is...

[eluser]kakallatt[/eluser]
I have the checkbox
Code:
<input type="checkbox" name="cid[]" value="8">
<input type="checkbox" name="cid[]" value="9">

How can I validate the checkbox is required?

[eluser]nickaceph[/eluser]
Hi, First of all thank you. for code igniter and the datamapper

finally, Ive decided to use CI and Datamapper for my project.

* CI - for its simplicity and ease of use and configuration even if may taunt it as sort of legacy code. it will fit my need

* DataMapper as ORM - for its functionality that fits with my requirements specially its iterator and overall core concept, fits perfectly with some adjustment for my project.

Now, I have started to dig deeper and plan for how my code will fit my needs. the first thing I need is I need to extend the Datamapper, so I can add functionality to its core class. but I dont want to alter any of the Datammaper code. I need to extend it like how the CI is extending the Controller and Model. Is it the same as CI, is this possible and can anyone give me a hint or sample.

My goal is a separation of code without altering the 3rd party. so I can upgrade/update it separately without any issue of complexity. like how Datamapper is plugin to CI.

- 1. Code Igniter
- 2. Data Mapper
- 3. My Core Code

I can update 1 without affecting or without the need to modify the others? Big Grin

Thanks

PS: I know i can use.create extension,

but I need to hookup something just right after the construct is that posible?

public function __construct()
{
--> $this->myinit()
}

is this posible with extend?





[eluser]Stolz[/eluser]
WanWizard

There is problem with DM related to using in_array() with loose comparison when the array has mixed numeric and non numeric keys.

For example, if you define this validation rule in one of your models
Code:
'some_number' => array(
'label' => 'Number',
'rules' => array('numeric', 'greater_than' => 0),
)

The rules array has mixed keys. If you take a look around line 2222 of datamapper.php you can see:
Code:
if ( ! $related && ! in_array('required', $rules) && ! in_array('always_validate', $rules)

Lets debug it
Code:
print_r($rules);
var_dump(in_array('required', $rules));
var_dump(in_array('always_validate', $rules));

Output:
Code:
Array
(
    [0] => numeric
    [greater_than] => 0
)
bool(true)
bool(true)

That brakes the documented behaviour
Quote:Important: When cascading rules, note that rules are not run on empty fields unless the required or always_validate rules are set.

This includes anything that evaluates to TRUE for the empty() function, including: '', FALSE, or 0.

In the above case, if you submit an empty field the validation rules are run in spite of not having 'required' nor 'always_validate' rules defined.

Changing in_array() to use strict comparison (third param to TRUE) fixes the problem. I changed it myself for the validation function but the problem it's likely to exist in some other places of the library.

[eluser]nickaceph[/eluser]
Hi,

Iam now in depth exploring your ORM, its nice and Iam currently building a pet project with it,
I now starting know how to thinker with the advance relations but there is one issue I really cant settle.
please help its a has_many to same object. ex:

table: users (id, username, ....)

this can be done in has_many relation where in you data will be in separate table like
table: users_childusers (id, user_id, childuser_id)

$has_many = array(
'childuser' => array(
'class' => 'user',
'other_field' => 'user'
),
'users' => array(
'other_field' => 'childuser'
)
);

what i want is somthing like this:

table: users (id, username, parentuser_id, ....)

relating it to the same table.
is this posible and how can it be done correctly.

thanks Big Grin

Nickace


[eluser]WanWizard[/eluser]
Yes, this is possible, check out http://datamapper.wanwizard.eu/pages/adv...tions.html, self relationships.

The example is a many-to-many, but a one-to-many is not a problem either.

[eluser]Unknown[/eluser]
Hi, I've been having trouble transferring a conditional join from a plain MYSQL query into datamapper.

My old query read as follows:
Code:
SELECT o.*, m.message
FROM offers o
LEFT JOIN messages m ON o.id = m.offer_id AND m.site_id = 1

Offers to messages is a one to many relationship, where there might not be any message records for an offer.

My problem is recreating the condition in the join, the 'm.site_id = 1'. I cant see anything in the ORM documentation that would allow you to attach a condition to your relationships.

I can't just add it as a where_related condition to the query as if the message record did not exist, the related offer record fields would not be returned.

Any light you could shine on this issue would be greatly appreciated.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB