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 This will generate Code: SELECT `contact`.* 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); Code: object(stdClass)[##] 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 {
[eluser]ahmetkapikiran[/eluser]
Code: $l->order_by("FIELD(id,7,8,1,4,5,6"); 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]
@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(); Code: Unknown column 'clinics_subquery.id' in 'where clause' Im pretty sure that problem is in the line 3063 Code: $table_pattern = '(?:' . preg_quote($this->table) . '|' . preg_quote($tablename) . '|\(' . preg_quote($tablename) . '\))';
[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. |
Welcome Guest, Not a member yet? Register Sign In |