Quellcode durchsuchen

Static values of the form array(array('relation')) are now rewritten to 'relation'.

Taddeus Kroes vor 13 Jahren
Ursprung
Commit
d24785f992
1 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. 24 0
      generate.py

+ 24 - 0
generate.py

@@ -140,15 +140,39 @@ class Model(object):
         self.belongs_to.append((singular, self.relopts(other_model)))
         other_model.add_has_relation(self)
 
+    def strip_array(self, attr):
+        array = getattr(self, attr)
+
+        if len(array) == 1:
+            relation, opts = array[0]
+
+            if not len(opts):
+                return php_static_var(attr, php_value(relation))
+
     def php_has_many(self):
+        stripped = self.strip_array('has_many')
+
+        if stripped:
+            return stripped
+
         if self.has_many:
             return php_static_array('has_many', self.has_many)
 
     def php_has_one(self):
+        stripped = self.strip_array('has_one')
+
+        if stripped:
+            return stripped
+
         if self.has_one:
             return php_static_array('has_one', self.has_one)
 
     def php_belongs_to(self):
+        stripped = self.strip_array('belongs_to')
+
+        if stripped:
+            return stripped
+
         if self.belongs_to:
             return php_static_array('belongs_to', self.belongs_to)