Soap Service Attribute And Model Relations

Hi all!

On the server side :




// If my model is (1-N relation between Foo and Bar) :

class Foo extends CActiveRecord {


	/**

	 * @var Bar[]  bars {nillable=false, minOccurs=1, maxOccurs=unbounded}

	 * @soap

	 */

	public $bars;

	

	// ...


	public function relations() {

		return array(

			'bars' => array(self::HAS_MANY, 'Bar', 'id_foo'),

		);

	}


	// ...


}


// then 

var_dump($foo->bars);

// always returns NULL, event if there actually are some related models in the database



When we declare the public attribute for the SOAP web service (to expose it in the WSDL) with the same name as the relation, we kind of mess up the model, resulting in the attribute always returning NULL…

Cheers!

Relations are read like properties but that requires to check if a property exist and then check if a relation by that name exists. That’s why when you declare it as a property it starts to ignore the real relation.

What you have to do is to extend the class generating WSDL to include relations along with ordinary properties. I’ve done that recently and it’s quite painless.