Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 3eb06a5

Browse files
author
Nik Barham
committed
Merge branch 'master' into pluggable
2 parents d6a5969 + be3aa10 commit 3eb06a5

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<img src='http://www.automatorm.com/img/logo.png?2'>
22

3-
4-
5-
automatorm [![Build Status](https://travis-ci.org/brokencube/automatorm.svg?branch=master)](https://travis-ci.org/brokencube/automatorm) [![Code Climate](https://codeclimate.com/github/brokencube/automatorm/badges/gpa.svg)](https://codeclimate.com/github/brokencube/automatorm)
3+
AutomatORM
64
==========
5+
[![Latest Stable Version](https://poser.pugx.org/brokencube/automatorm/v/stable)](https://packagist.org/packages/brokencube/automatorm)
6+
[![Build Status](https://travis-ci.org/brokencube/automatorm.svg?branch=master)](https://travis-ci.org/brokencube/automatorm)
7+
[![Code Climate](https://codeclimate.com/github/brokencube/automatorm/badges/gpa.svg)](https://codeclimate.com/github/brokencube/automatorm)
78

89
A simple to use ORM in PHP, that reads your database schema directly, without having to run code generators, or create schema documents.
910

1011
Requirements:
11-
PHP 5.4 + PDO, composer
12+
PHP 5.6 + PDO, composer

src/Orm/Data.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,46 @@ public function __clone()
6969
$this->__external = array();
7070
}
7171

72-
// Create a open cloned copy of this object, ready to reinsert as a new row.
73-
public function duplicate()
72+
/**
73+
* Create a open cloned copy of this object, ready to reinsert as a new row.
74+
*
75+
* @param bool $clone_M2M_properties Clone M2M properties as well
76+
* @return self
77+
*/
78+
public function duplicate($clone_M2M_properties = false)
7479
{
7580
$clone = clone $this;
7681
$clone->__new = true;
7782
$clone->__delete = false;
7883
unset($clone->__data['id']);
84+
85+
// Clone M-M joins
86+
if ($clone_M2M_properties) {
87+
foreach ($this->__model['many-to-many'] as $key => $model) {
88+
$clone->__external[$key] = $this->{$key};
89+
}
90+
}
91+
7992
return $clone;
8093
}
94+
95+
/**
96+
* Lock id of the object. Once locked, this data object will always represent the id specified.
97+
*
98+
* @return self
99+
*/
81100

82101
public function lock()
83102
{
84103
$this->__locked = true;
85104
return $this;
86105
}
87106

107+
/**
108+
* Mark data object for deletion when commited
109+
*
110+
* @return self
111+
*/
88112
public function delete()
89113
{
90114
if ($this->__new) {
@@ -601,7 +625,7 @@ public function __set($var, $value)
601625
} elseif ($value instanceof Model) {
602626
// Trying to pass in the wrong table for the relationship!
603627
// That is, the table name on the foreign key does not match the table name in the passed Model object
604-
$value_table = Schema::normaliseCase($value->data(true)->__table);
628+
$value_table = Schema::normaliseCase($value->dataOriginal()->__table);
605629
$expected_table = $this->__model['many-to-one'][$var];
606630

607631
if ($value_table !== $expected_table) {

src/Orm/Model.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,14 @@ public function __wakeup()
380380
return $this;
381381
}
382382

383-
final public function data($returnOriginal = false)
383+
final public function data()
384384
{
385-
if ($returnOriginal) {
386-
return $this->_data;
387-
} else {
388-
return clone $this->_data;
389-
}
385+
return clone $this->_data;
386+
}
387+
388+
final public function dataOriginal()
389+
{
390+
return $this->_data;
390391
}
391392

392393
// Swap out the Data object in this Model for an updated one (i.e. after doing an update)

0 commit comments

Comments
 (0)