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-30-2012

[eluser]WanWizard[/eluser]
And this doesn't?
Code:
$config[‘db_params’] = "";

The only different is that FALSE does
Code:
$this->db =& $CI->db;

while TRUE ( or "" ) does:
Code:
$this->db = clone($CI->db);



DataMapper ORM v1.8.0 - El Forum - 05-30-2012

[eluser]costicanu[/eluser]
it was $config[‘db_params’] = "" and didn't worked. Now it's $config[‘db_params’] = FALSE

and works! Thanks again!


DataMapper ORM v1.8.0 - El Forum - 05-30-2012

[eluser]WanWizard[/eluser]
Well, that's odd, because it's the default and it has been for years.

I can not believe that cloning an object would switch a parameter setting, it seems impossible to me.

What version of CI are you using, and what version of Datamapper (exactly, and installed from where)?




DataMapper ORM v1.8.0 - El Forum - 06-14-2012

[eluser]JamieBarton[/eluser]
Hi guys

I'm after a bit of help.

I have an events site I'm wanting to view the events made by me and my friends.

Friends table:

id / user_id / friend_id

Events table

id / name / user_id


How do I query for the events made by me and my friends?

Can't seem to figure out where to start!


Regards


DataMapper ORM v1.8.0 - El Forum - 06-14-2012

[eluser]WanWizard[/eluser]
create an array with your user_id and all the user_id's of your friends. Then run a where_in() query on the events model.


DataMapper ORM v1.8.0 - El Forum - 06-14-2012

[eluser]JamieBarton[/eluser]
Hi,

I'm new to DataMapper..

[quote author="WanWizard" date="1339679428"]create an array with your user_id and all the user_id's of your friends. Then run a where_in() query on the events model.[/quote]

Code:
$friends = new Friend();
  $friends->get_by_friend_id($this->user->id);

Then..

Code:
$events = new Event();
  $events->where('end_date >=', date('m-d-Y'));
  $events->order_by('start_date', 'asc');
  $events->order_by('start_time', 'asc');
  $events->where_in('user_id', $friends);
  $this->data['events'] = $events->get_iterated();

Nearly there? Thanks for your help!


DataMapper ORM v1.8.0 - El Forum - 06-14-2012

[eluser]WanWizard[/eluser]
You now select only your friends, but not yourself.

So would add
Code:
$events->or_where('user_id', $this->user->id);
to include yourself.


DataMapper ORM v1.8.0 - El Forum - 07-04-2012

[eluser]jez123[/eluser]
Hi

How can I include multiple columns in a join, for example the following query

Code:
select * from a left outer join b ON a.id = b.a_id AND b.b_id = 23;

The following will create the join, but I can't work out how to add another column on the join!

Code:
include_related('b',array('id'),TRUE)

I've really been struggling trying to work out how to do this. Thanks if you can help!



DataMapper ORM v1.8.0 - El Forum - 07-05-2012

[eluser]WanWizard[/eluser]
Code:
include_related('b',array('id', 'this', 'that'),TRUE)
should work without problems.

Or do you mean the join criteria (which has nothing to do with including columns)?

For that, the answer is "You can't". Datamapper is an ORM, and maintains it's relations based on the PK-FK connection. Which is what is used to join two related tables.

This specific example could be solved with a WHERE:
Code:
where_related('b', 'id', 23)
resulting in
Code:
select * from a left outer join b ON a.id = b.a_id WHERE b.id = 23;



DataMapper ORM v1.8.0 - El Forum - 07-05-2012

[eluser]jez123[/eluser]
Thanks for your help. That query is completely different from having an AND because not only of efficiency

http://greensweater.wordpress.com/2008/09/09/mysql-left-join-with-multiple-conditions/

But also if you have multiple joins then including the condition in the where part of the query will return a completely different result set

I'm surprised it can't be done actually, because the query restricts the result set to a specific criteria (e.g., 23 is the value of a logged in user in the session), so it should have nothing to do with foreign key constraints, and is quite commonly done in SQL. Guess I'll have to write my own function in the datamapper library or get rid of it for something less restrictive.