|
@@ -140,15 +140,39 @@ class Model(object):
|
|
|
self.belongs_to.append((singular, self.relopts(other_model)))
|
|
self.belongs_to.append((singular, self.relopts(other_model)))
|
|
|
other_model.add_has_relation(self)
|
|
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):
|
|
def php_has_many(self):
|
|
|
|
|
+ stripped = self.strip_array('has_many')
|
|
|
|
|
+
|
|
|
|
|
+ if stripped:
|
|
|
|
|
+ return stripped
|
|
|
|
|
+
|
|
|
if self.has_many:
|
|
if self.has_many:
|
|
|
return php_static_array('has_many', self.has_many)
|
|
return php_static_array('has_many', self.has_many)
|
|
|
|
|
|
|
|
def php_has_one(self):
|
|
def php_has_one(self):
|
|
|
|
|
+ stripped = self.strip_array('has_one')
|
|
|
|
|
+
|
|
|
|
|
+ if stripped:
|
|
|
|
|
+ return stripped
|
|
|
|
|
+
|
|
|
if self.has_one:
|
|
if self.has_one:
|
|
|
return php_static_array('has_one', self.has_one)
|
|
return php_static_array('has_one', self.has_one)
|
|
|
|
|
|
|
|
def php_belongs_to(self):
|
|
def php_belongs_to(self):
|
|
|
|
|
+ stripped = self.strip_array('belongs_to')
|
|
|
|
|
+
|
|
|
|
|
+ if stripped:
|
|
|
|
|
+ return stripped
|
|
|
|
|
+
|
|
|
if self.belongs_to:
|
|
if self.belongs_to:
|
|
|
return php_static_array('belongs_to', self.belongs_to)
|
|
return php_static_array('belongs_to', self.belongs_to)
|
|
|
|
|
|