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

[eluser]WanWizard[/eluser]
@sim23,

My first thought was that it was related to the fact that you use a table prefix. So the parse method regex couldn't find and replace that alias.

But when I tried to write a test case here, I noticed that I can't reproduce this error. When I run a query like that, it creates the JOIN without a table alias, thus avoiding this issue.

To make sure it's not a bug already fixed, pull the latest datamapper library from http://bitbucket.org/wanwizard/datamapper.

[eluser]WanWizard[/eluser]
[quote author="coldscooter" date="1337970895"]Is anyone able to provide a basic example of a join using DataMapper? I don't see any clear example of it in the manual.[/quote]
With Datamapper you don't need to join, Datamapper will do that for you.

Consider something like this:
Code:
// users -> one-to-many -> contacts

// get user 1, and load all it's contacts
$user = new User(1);
$user->contact->get();

This will generate
Code:
SELECT `contact`.*
FROM (`contact`)
LEFT OUTER JOIN `user` user ON `contact`.`id` =
`user`.`contact_id`
WHERE `user`.`id` = 1

This is because Datamapper is aware of the relations between models, and how they are related.

[eluser]Jacob F.[/eluser]
Hi WanWizard,

I work with coldscooter, and I just tried what you suggested and got the right object but null data:

say the structure of contacts is
Code:
id || user_id || pnom || nom || rel

When I do
Code:
var_dump($user->contact->get()->stored);
the output is

Code:
object(stdClass)[##]
public 'id' => null
public 'user_id' => null
public 'pnom' => null
public 'nom' => null
public 'rel' => null

However doing a get() on each table returns as expected (with data).

In our case, we're doing Languages and Publications, and the model is:

Code:
class Language extends DataMapper {
var $has_many = array("publication");
function __construct(...) {
  ...
}

[eluser]ahmetkapikiran[/eluser]
Code:
$l->order_by("FIELD(id,7,8,1,4,5,6");
syntax error Sad
Code:
ORDER BY FIELD(id, `7`, `8`, `1`, `4`, `5`, `6)`

OR
Code:
$l->order_by_func('FIELD',array('@id',array(7,8,1,4,5,6)),false);

Syntax Error
Code:
ORDER BY FIELD(`id`.`type` 7 8 1 4 5 6)

[eluser]WanWizard[/eluser]
@Jacob F,

What is 'stored'? Datamapper doesn't return stdClasses, so I'm not sure what you're trying to do.

[eluser]WanWizard[/eluser]
@ahmetkapikiran,

This is probably CI's order_by() method that tries to escape the fields. you can test that by writing a standard $this->db query.

I have no time to look for a workaround atm, let me know if CI exhibits the same behaviour.

[eluser]Andrea Coronese[/eluser]
I figured out the problem I was having. Since DataMapper uses form_validation, and since form_validation loads a lang for error messages, the fact that I set my config['language'] to a language that was NOT english screwed everything up. Copying the lang file from english to desired language folder did the trick

[eluser]smi23[/eluser]
[quote author="WanWizard" date="1337974818"]@sim23,

My first thought was that it was related to the fact that you use a table prefix. So the parse method regex couldn't find and replace that alias.

But when I tried to write a test case here, I noticed that I can't reproduce this error. When I run a query like that, it creates the JOIN without a table alias, thus avoiding this issue.

To make sure it's not a bug already fixed, pull the latest datamapper library from http://bitbucket.org/wanwizard/datamapper.
[/quote]
Thanks for a reply!
I have the latest version.
I tried more simple code
Code:
$clinics = new Clinic();
$clinics->include_related_count('clinic_service')->get();
    
foreach ($clinics as $clinic) {
    echo $clinic->name . ' ' . $clinic->clinic_service_count . ' <br />';
}
And it returns me
Code:
Unknown column 'clinics_subquery.id' in 'where clause'

SELECT `ci_clinics`.*, (SELECT COUNT(*) AS count FROM (`ci_clinic_services`)
  LEFT OUTER JOIN `ci_clinics` clinics ON `clinics_subquery`.`id` = `ci_clinic_services`.`clinic_id`
  WHERE `clinics_subquery`.id = `clinics`.`id`) AS clinic_service_count FROM (`ci_clinics`)

Filename: /var/www/vhosts/myebooking.dk/httpdocs/myebookingdev/libraries/datamapper.php

Line Number: 1328
Tested it without table prefix - ok.
Im pretty sure that problem is in the line 3063
Code:
$table_pattern = '(?:' . preg_quote($this->table) . '|' . preg_quote($tablename) . '|\(' . preg_quote($tablename) . '\))';
// (?:clinics|`clinics`|\(`clinics`\))
Pattern has no prefixes.

[eluser]WanWizard[/eluser]
The problem is that the JOIN is created with an alias without the prefix, so the pattern doesn't match on the alias.

I think this is caused because you have defined the prefix in your database.php, but not in your datamapper config file. So Datamapper is not aware of the prefix.

I can reproduce it that way, and solve it by defining the same prefix in the datamapper config.

[eluser]smi23[/eluser]
[quote author="WanWizard" date="1338209448"]The problem is that the JOIN is created with an alias without the prefix, so the pattern doesn't match on the alias.

I think this is caused because you have defined the prefix in your database.php, but not in your datamapper config file. So Datamapper is not aware of the prefix.

I can reproduce it that way, and solve it by defining the same prefix in the datamapper config.[/quote]
F*ck! How did I miss that??

Big thanks Harro! Sorry for taking time.




Theme © iAndrew 2016 - Forum software by © MyBB