/** * Enables the use of build|create for associations. * * @param string $method Name of method * @param mixed $args Method args * @return mixed An instance of a given {@link AbstractRelationship} */ public function __call($method, $args) { //check for build|create_association methods if (preg_match('/(build|create)_/', $method)) { if (!empty($args)) { $args = $args[0]; } $association_name = \str_replace(['build_', 'create_'], '', $method); $method = \str_replace($association_name, 'association', $method); $table = static::table(); if (($association = $table->getRelationship($association_name)) || ($association = $table->getRelationship($association_name = Utils::pluralize($association_name)))) { // access association to ensure that the relationship has been loaded // so that we do not double-up on records if we append a newly created $this->{$association_name}; return $association->{$method}($this, $args); } } throw new ExceptionActiverecord("Call to undefined method: {$method}"); }
public function tableize($s) { return Utils::pluralize(\strtolower($this->underscorify($s))); }