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

[eluser]goddestroyer[/eluser]
lets say that our products are camera lenses. an example of a productspecifications are: objective size, focal length, max zoom... these are not stored as columns of the products table because the specifications themselves are variable (hence the specification_id in the productspecifications table).

furthermore, each specification may come in 3 flavors-- the value it has in the draft stage, the value it has in the engineering department, and the advertised marketing value, hence the "specificationsection_id" in our productspecifications table.

the application where the question arises, is suppose someone is searching for camera lenses and they check boxes that indicate they are only interested in lenses of objective size 50 AND max-zoom of 10.

[eluser]WanWizard[/eluser]
I don't see an immediate solution for this using standard DM methods.

You're best bet (and certainly the quickest) is to add a custom method to your model, do a standard $this->db->query. Pass the result to $this->_process_query(), which is a DM method that converts CI's AR results into DM objects.

[eluser]fillipe.bs[/eluser]
Just to share with the people in the community, if you are having the following error when trying to join CIUnit and DataMapper ORM:

Fatal error: Call to undefined method CI_DB_mysql_driver :: dm_call_method () in ...

The following link solved my problem:

https://bitbucket.org/kenjis/my-ciunit/i...21-in-test

[eluser]JamieBarton[/eluser]
Hi guys,

What I'm trying to do is show friends on the profile of someone. The table for friends is set out like.

id / user_id / friend_id

I have the following code in my controller:

Code:
$friends = new Friend();
  $friends->where('user_id', $user->id);
  $friends->where('approved', 1);
  $this->data['friends'] = $friends->get();

What I'm struggling to do is figure out how I would like friend_id to the user table.

So in my view I can put:

Code:
<?php foreach($friends as $f): ?>

<?=$f->user->first_name;?>

<?php endforeach; ?>

Would appreciate any help Smile

Regards,
Jamie

[eluser]WanWizard[/eluser]
What you basically want is a many-to-many self referencing relationship for the users model.

This means you need a users_users relationship table which contains the user_id and friend_id columns.

You then define the model like so:
Code:
class User extends DataMapper {
    $has_many = array(
        'friend' => array(
            'class' => 'user',
            'other_field' => 'user',
        ),
        'user' => array(
            'other_field' => 'friend',
        )
    );
}

You can then do
Code:
// fetch a user (with id = 1)
$user = new User(1);

// fetch this users friends
$user->friend->get();

// who are your friends friends?
foreach ($user->friend as $f)
{
    $f->friend->get();
}

// who also has your friends?
// who are your friends friends?
foreach ($user->friend as $f)
{
    $f->user->get();
}

[eluser]insert_hilarity_here[/eluser]
Hi

If I am posting this in the wrong place let me know! I am using ver 1.8.2.1 of Datamapper

Anyways with Codeignier 2.1.1 there has been an update to DB_driver.php due to CI Bug #1387.

Beginning on line 1266 of DB_driver.php in the system/database folder here is the new code:

Code:
// Convert tabs or multiple spaces into single spaces
  $item = preg_replace('/\s+/', ' ', $item);

  // If the item has an alias declaration we remove it and set it aside.
  // Basically we remove everything to the right of the first space
  if (preg_match('/^([^\s]+) (AS )*(.+)$/i', $item, $matches))
  {
   $item = $matches[1];

   // Escape the alias
   $alias = ' '.$matches[2].$this->_escape_identifiers($matches[3]);
  }
  else
  {
   $alias = '';
  }

This effects code written in Datamapper I believe.

Example

Code:
$user->where('updated_on >=', '2012-06-13 00:00:00')->get();

will now produce

Code:
SELECT * FROM (`users`) WHERE `users`.`updated_on` `>=` '2012-06-13 00:00:00'

the issue being its escaping the operator, so the query will fail.

On the datamapper documentation site this page: http://datamapper.wanwizard.eu/pages/get.html

this code

Code:
$o = new Object();
$o->where('name !=', $name);
$o->where('id <', $id);

will now fail in Codeigniter 2.1.1

I do not have a good workaround yet.

[eluser]WanWizard[/eluser]
I suggest you look at the fix then, because Datamapper doesn't build it's own queries, it uses CI'a Active Record library, which maps the where() in a DM model directly to $this->db->where().

Looking at that bit of code, it is related to column name aliases, which is not relevant to your example.

And officially Datamapper only supports 2.1.0. Is has not been tested on later versions, and given the changes to the core, it is very likely there will be issues in 2.1.1.

[eluser]insert_hilarity_here[/eluser]
I obviously posted this in the wrong place because it effects all queries in Codeigniter, not just datamapper.

The bug is its picking up the operator as an alias, because the only reserved identifier in active record is *

The bug is on github at https://github.com/EllisLab/CodeIgniter/issues/1469

[eluser]WanWizard[/eluser]
Looking at the regex, I think the issue is in the
Code:
(AS )*
where the star indicates zero or more times. So the preg_match() also matches when there is no "AS" in the string.

Looks like a botch job. I've commented on the github issue.

[eluser]WanWizard[/eluser]
I get Datamapper running again by changing line 1270 of DB_driver.php to read
Code:
if (preg_match('/^([^\s]+) (AS )*([^\s]+)$/i', $item, $matches))




Theme © iAndrew 2016 - Forum software by © MyBB