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

[eluser]maikens[/eluser]
I'm not sure if anyone is still responding to this thread, but just in case: I'm wondering what the correct way of setting up a one-to-one relationship with a defined parent and child is. The way I have been doing it is similar to this:

Code:
class Customer ... {

public $has_one = array('address');

}
Code:
class Address ... {

public $has_one = array('customer');

}

with the Customer being the parent (ie, has either one or zero Addresses) and the address being the child (always has one Customer). In the database I have a customer_id on addresses which is not null, indexed and associated with customer.id and set to CASCADE on update and delete , and address_id on customers which is null and associated with address.id and set to NO ACTION on update and delete.

Is this the proper configuration for a CI Datamapper one-to-one-or-zero (parent/child) relationship?

[eluser]teomor[/eluser]
Hello there.
I've been thinking of using this ORM for my next project, but there's something really important that's bugging me, which is Transactions!
The sole purpose of transactions is to make several changes in the DB at once. So, if I want to save a on object and it's many related objects altogether, How would I achieve that in DataMapper?

[eluser]Unknown[/eluser]
Hey all,

I hope someone here can help me.
I've been working with Datamapper ORM for a while now and was wondering about something.... Loose coupling....

For instance: I have a plugin 'comments'.... Comments should not care about all other classes I have, it should simply take the ID of the current item, and the name of the current class ( Article for instance) and save that to the DB.

I guess my comment table would look something like this:
id (int)
user_id (int)
class_type (varchar) - might be: article, image, etc.
class_id (int) - id of the article/image etc. being commented on
comment (text)
created (datetime)
updated (datetime)

Is this possible in Datamapper ORM while still retaining the ability of $articles->comments->get(); ??

How would you deal with this?


Regards,
LostDreamer

[eluser]teomor[/eluser]
Quick question about JSON. I want to include related objects in the JSON object, but I can't understand why the following code works (I get the full Photo object in the result):
Code:
$venues = new Venue();
$venues->like('name', $this->input->get('term'));
$venues->include_related('photo', null, true, true);
$venues->get();
foreach ($venues as $venue) {
$autocomplete_items[] = array(
  'value' => $venue->id,
  'label' => $venue->name,
  'venue' => $venue
);
}
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($autocomplete_items));
but this one throws a 'recursion detected' error:
Code:
$event = new Event();
$event->where('id', $event_id);
$event->include_related('venue', null, true, true);
$event->get();
echo json_encode($event);

[eluser]Maglok[/eluser]
Hey all! Still using datamapper. still awesome. I have now gotten to a situation I don't know how to deal with.

I have a object with some relations: A project with a domain, department, status. These are thus all different tables.

I can do the following:
Code:
$this->where_related_domain('id', 5);
This works swimmingly, does a join and then a where with a domain.id = 5.

Thing is I want to stack AND and OR.

Code:
where (domain.id = 5 OR domain.id = 7) AND (department.id = 3 OR department.id =5)

I would normally solve that by writing my own where like so:
Code:
$this->where("(domain.id= '5' OR domain.id = '7') AND (department.id = 3 OR department.id = 5));

Thing is, this a relation so that won't work cause there is no join yet. I can use it like this:
Code:
$this->where_related_domain("(domain.id= '5' OR domain.id = '7') AND (department.id = 3 OR department.id = 5));

But that brings all kinds of nightmares with it.

Is there anyway in Datamapper to do this without resorting to writing the entire query through $this->query();?

[eluser]teomor[/eluser]
Did you try the group_start and group_end functions? I have no idea if they have equivalents for relations, just wondering what I would do in such a situation.. Smile

[eluser]Maglok[/eluser]
This is awesome I never knew those functions did that. I guess I was reading with my nose. Thanks!

[eluser]imohammad[/eluser]
Hey guys!

Question, using $object->select('id, username, email'); retrieves the values of these selected attributes, however ORM still retrieves the other attributes but with NULL values. Is there a way to only retrieve the selected values?

Thanks!

[eluser]Maglok[/eluser]
@imohammad: As far as I know it does not retrieve it from the database (check your check_last_query()) but it does have the empty values, because those are defined by the columns in the database. There is no real reason you would not need that. But the select from the database does actually leave it out and do a proper select (it uses codeigniter's active record).

---------------------------------------------

Now! I have a question myself! I am trying to code some defaults for when people make a certain object in the user interface. I got something like this:

Code:
// Get the values from the config file
  $this->CI->load->config('leerlijnen');
  $defaults = $this->CI->config->item('default_leerlijn');
  
  // Create categorieen
  foreach($defaults['categorieen'] as $c)
  {
   $categorie = new Categorie();
   $categorie->from_array($c);
   //TODO
  }

unset($defaults['categorieen']);

$this->from_array($defaults);
  
  return $this;

The thing is, how can I assign a relationship to a datamapper object without saving? These things are supposed to be defaults that the user changes and submits. They should not appear in the database.

[eluser]Maglok[/eluser]
We have decided to not save it, that is not the purpose of datamapper.

I do have a new question!

I have a object A. A has a related instance of A. So A has many A.

A also has a set of Bs.

Is there a way for me to combine the Bs from A and from its related As into a combined variable? Without writing all the query code manually?




Theme © iAndrew 2016 - Forum software by © MyBB