Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]WanWizard[/eluser]
[quote author="Jacob F." date="1341679090"]That's what I figured :/

Is that fk issue what's causing DataMapper to think there is a many-to-many relationship[/quote]
Datamapper contains logic to see how the relationship is defined, as it supports join tables even for one-to-one relations.

It does that by looking at the PK's and FK's in the relationship definition, and if they are not found in the related tables, assume you have a join table that contains the FK's.

This is the case here, as the generated FK is wrong so it can't be found.

[eluser]Jacob F.[/eluser]
Damn :/

Thanks for the insight!

[eluser]Mark LaDoux[/eluser]
Sorry to hear that you are dropping this. I'd take it over, but I neither have the time nor the skill. I love this library, and hope someone decent picks it up for you.

[eluser]WanWizard[/eluser]
[quote author="Mark LaDoux" date="1341782265"]Sorry to hear that you are dropping this. I'd take it over, but I neither have the time nor the skill. I love this library, and hope someone decent picks it up for you.[/quote]
Who is dropping what?

I'm not dropping anything, I've only postponed development on 2.0 (which will be an entirely new codebase) until it's clear where CI 3 is heading...

[eluser]Jacob F.[/eluser]
I think there might be a bug in where_between(): it doesn't enclose dates with quotes (which causes the database to perform a mathematical operation):

Code:
# www.example.com/?range[0]=2012-07-04⦥[1]=2012-07-06

$range = ( isset($_GET['range']) )? $_GET['range'] : array( 'SYSDATE() - INTERVAL 30 DAY' , 'SYSDATE()');

$orders->where_between('date', $range[0], $range[1])->get();

#result:

SELECT * FROM `orders` WHERE `date` BETWEEN 2012-07-04 AND 2012-07-06;

But

Code:
$orders->where_between('date',"'".$range[0]."'","'".$range[1]."'")->get();

#result:

SELECT * FROM `orders` WHERE `date` BETWEEN '2012-07-04' AND '2012-07-06';

Also, (string)$range[0] and "{$range[0]}" don't produce quoted strings.

[eluser]WanWizard[/eluser]
Well spotted, and thanks for reporting it.

Fixed: https://bitbucket.org/wanwizard/datamapp...e9af373d9c

If you're on 1.8.2, you can apply this fix to your version of Datamapper, or download the latest from bitbucket.

[eluser]Jacob F.[/eluser]
Wow, that was fast--thanks!

[eluser]BrainFeeder[/eluser]
I have troubles getting/deleting related data when the tables are in different databases.

Code:
class Company extends DataMapper {

var $model = 'company';
var $table = 'companies';
var $prefix = "tbl_";

var $db_params = 'superadmin';

var $has_many = array('user');
....

Code:
class User extends DataMapper {

var $model = 'user';
var $table = 'users';
var $prefix = "app_";

var $db_params = 'default';

var $has_one = array('company');
...

Now when I try to get the related company from a user like this:

Code:
...
if($u->login()) {
  $u->company->get();
  $cid = $u->company->id;
...
}
...

I get the error : "Table does not exist".
Datamapper looks for the users table in the database where the companies table is while I've set different db_params for both models.

Did I forget something? Or doesn't datamapper support cross database joins?

[eluser]cahva[/eluser]
I have not tried cross database joins with datamapper but what SQL does it give you when you try this:
Code:
echo $u->company->get_sql();
Are the db_params added correctly?

[eluser]BrainFeeder[/eluser]
It prints
Code:
SELECT * FROM (`tbl_companies`)

Shouldn't there be a WHERE part ?

If I do
Code:
$u->company->get();

I get the error:
Code:
A Database Error Occurred

Error Number: 1146

Table 'a1210alf_beheer.app_users' doesn't exist

SELECT `tbl_companies`.* FROM (`tbl_companies`) LEFT OUTER JOIN `app_users` app_users ON `tbl_companies`.`id` = `app_users`.`company_id` WHERE `app_users`.`id` = 5

As you can see the format isn't database.table.field , just table.field




Theme © iAndrew 2016 - Forum software by © MyBB