[Pkg-owncloud-commits] [owncloud-doc] 198/227: Update database.rst

David Prévot taffit at moszumanska.debian.org
Sat Oct 11 17:20:49 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit e0698a93398372782f3efe44f461cfa4b800cacc
Author: Bernhard Posselt <Raydiation at users.noreply.github.com>
Date:   Thu Oct 2 16:49:28 2014 +0200

    Update database.rst
---
 developer_manual/app/database.rst | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/developer_manual/app/database.rst b/developer_manual/app/database.rst
index 06f71bb..2580ce6 100644
--- a/developer_manual/app/database.rst
+++ b/developer_manual/app/database.rst
@@ -223,6 +223,48 @@ Since all attributes should be protected, getters and setters are automatically
     $author->setId(3);
     $author->getPhoneNumber()  // null
 
+Custom attribute to database column mapping
+-------------------------------------------
+
+By default each attribute will be mapped to a database column by a certain convention, e.g. **phoneNumber** 
+will be mapped to the column **phone_number** and vice versa. Sometimes it is needed though to map attributes to
+different columns because of backwards compability. To define a custom 
+mapping, simply override the **columnToProperty** and **propertyToColumn** methods of the entity in question:
+
+.. code-block:: php
+
+
+    <?php
+    // db/author.php
+    namespace OCA\MyApp\Db;
+
+    use \OCP\AppFramework\Db\Entity;
+
+    class Author extends Entity {
+        protected $stars;
+        protected $name;
+        protected $phoneNumber;
+
+        // map attribute phoneNumber to the database column phonenumber
+        public function columnToProperty($column) {
+            if ($column === 'phonenumber') {
+                return 'phoneNumber';
+            } else {
+                return parent::columnToProperty($column);
+            }
+        }
+
+        public function propertyToColumn($property) {
+            if ($column === 'phoneNumber') {
+                return 'phonenumber';
+            } else {
+                return parent::propertyToColumn($property);
+            }
+        }
+
+    }
+    
+    
 Slugs
 -----
 Slugs are used to identify resources in the URL by a string rather than integer id. Since the URL allows only certain values, the entity baseclass provides a slugify method for it:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list