<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity repository-class="Rapsys\AirBundle\Repository\SessionRepository" name="Rapsys\AirBundle\Entity\Session" table="sessions">
    <id name="id" type="integer" column="id">
		<generator strategy="AUTO" />
		<options>
		  <option name="unsigned">true</option>
		</options>
    </id>
    <field name="date" type="date" />
    <field name="begin" type="time" nullable="true" />
    <field name="length" type="time" nullable="true" />
    <field name="premium" type="boolean" nullable="true" />
    <field name="rainfall" type="float" nullable="true" />
    <field name="rainrisk" type="float" nullable="true" />
    <field name="realfeel" type="float" nullable="true" />
    <field name="realfeelmin" type="float" nullable="true" />
    <field name="realfeelmax" type="float" nullable="true" />
    <field name="temperature" type="float" nullable="true" />
    <field name="temperaturemin" type="float" nullable="true" />
    <field name="temperaturemax" type="float" nullable="true" />
	<field name="locked" type="datetime" nullable="true" />
	<field name="created" type="datetime" />
	<field name="updated" type="datetime" />
	<many-to-one field="location" target-entity="Rapsys\AirBundle\Entity\Location" inversed-by="sessions" fetch="LAZY" />
	<many-to-one field="slot" target-entity="Rapsys\AirBundle\Entity\Slot" inversed-by="sessions" fetch="LAZY" />
    <one-to-many field="applications" target-entity="Rapsys\AirBundle\Entity\Application" mapped-by="session" fetch="LAZY" />
	<one-to-one field="application" target-entity="Rapsys\AirBundle\Entity\Application" fetch="LAZY" />
	<!--
    oneToOne:
        application:
            targetEntity: Rapsys\AirBundle\Entity\Application
	-->
	<indexes>
      <!--XXX: used in SessionRepository::findAllByPeriodAsCalendarArray-->
      <index name="date_location" columns="date,location_id" />
	  <!--XXX: used in SessionRepository::findAllPendingApplication-->
      <index name="locked_date_begin_created" columns="locked,date,begin,created" />
	  <!--XXX: used in SessionRepository::findBestApplicationById(s3)-->
	  <index name="application_locked_date_begin_slot_created" columns="application_id,locked,date,begin,slot_id,created" />
	  <!--XXX: candidated in findAllPendingDailyWeather and findAllPendingHourlyWeather-->
      <index name="location_date_begin_length_slot" columns="location_id,date,begin,length,slot_id" />
	  <!--
#        #XXX: tried for SessionRepository::findBestApplicationById(s2)
#        location_slot_application_locked_date_begin:
#            columns: [ location_id, slot_id, application_id, locked, date ]
#        #XXX: tried for SessionRepository::findBestApplicationById(s3)
#        application_locked_date:
#            columns: [ application_id, locked, date ]
#        #XXX: tried for SessionRepository::findBestApplicationById(s4)
#        location_application_locked_date:
#            columns: [ location_id, application_id, locked, date ]
	  -->
    </indexes>
	<unique-constraints>
      <unique-constraint name="date_location_slot" columns="date,location_id,slot_id" />
    </unique-constraints>
	<lifecycle-callbacks>
      <lifecycle-callback type="preUpdate" method="preUpdate" />
    </lifecycle-callbacks>
  </entity>
</doctrine-mapping>
