<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<database name="bookstore-behavior" defaultIdMethod="native" package="behavior.aggregate">

	<table name="aggregate_post" phpName="AggregatePost">
		<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
		<behavior name="aggregate_column">
			<parameter name="name" value="nb_comments" />
			<parameter name="expression" value="COUNT(id)" />
			<parameter name="foreign_table" value="aggregate_comment" />
		</behavior>
	</table>

	<table name="aggregate_comment" phpName="AggregateComment">
		<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
		<column name="post_id" type="INTEGER" />
		<foreign-key foreignTable="aggregate_post" onDelete="setnull" onUpdate="cascade">
			<reference local="post_id" foreign="id" />
		</foreign-key>
	</table>

	<table name="aggregate_poll" phpName="AggregatePoll">
		<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
		<behavior name="aggregate_column">
			<parameter name="name" value="total_score" />
			<parameter name="expression" value="SUM(score)" />
			<parameter name="foreign_table" value="aggregate_item" />
		</behavior>
	</table>

	<table name="aggregate_item" phpName="AggregateItem">
		<column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
		<column name="score" defaultValue="0" type="INTEGER" />
		<column name="poll_id" type="INTEGER" />
		<foreign-key foreignTable="aggregate_poll" onDelete="setnull" onUpdate="cascade">
			<reference local="poll_id" foreign="id" />
		</foreign-key>
	</table>

</database>
