Come faccio a trovare un elenco delle sottoclassi per un modello Propel con l'ereditarietà concreta

StackOverflow https://stackoverflow.com/questions/3826136

  •  26-09-2019
  •  | 
  •  

Domanda

Sto costruendo una mini-cms per il mio ente di beneficenza locale (sì, lo so che potrei usare un progetto di filo interdentale, ma vogliono personalizzato codificato)

Il mio schema di Propel attualmente si presenta come tale: -

<?xml version="1.0" encoding="UTF-8"?>
<database name="sja" defaultIdMethod="native">
    <table name="section">
        <column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" />
        <column name="title" type="VARCHAR" required="true" />
        <column name="slug" type="VARCHAR" required="true" />
    </table>
    <table name="page">
        <column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" />
        <column name="title" type="VARCHAR" required="true" />
        <column name="section_id" type="INTEGER" required="true" />
        <foreign-key foreignTable="section">
            <reference local="section_id" foreign="id" />
        </foreign-key>
    </table>
    <table name="static_page">
        <behavior name="concrete_inheritance">
            <parameter name="extends" value="page" />
        </behavior>
        <column name="content" type="LONGVARCHAR" required="true" />
    </table>
    <table name="home_page">
        <behavior name="concrete_inheritance">
            <parameter name="extends" value="page" />
        </behavior>
        <column name="standfirst_title" type="VARCHAR" />
        <column name="standfirst_image" type="VARCHAR" />
        <column name="standfirst_content" type="VARCHAR" />
    </table>

</database>

Voglio essere in grado di ottenere un elenco che includa "home_page" e "static_page" -., Senza dover creare manualmente ogni volta aggiungo un nuovo tipo di pagina

C'è un modo semplice per ottenere una lista come questa, o devo scrivere alcune cose di magia con le classi Riflesso, etc?

È stato utile?

Soluzione

Dopo un poke nella giusta direzione da #propel su freenode - mi è venuta in mente questo per un concetto di base - non hanno provato ancora però

function getSubClasses()
{
    $map = $this->getDatabaseMap();
    $children = array();
    foreach ($map->getRelations() AS $relation)
    {
        $behaviours = $relation->getRightTable()->getBehaviours();

        if (issset($behaviours['concrete_inheritance']['extends']) AND $behaviours['concrete_inheritance']['extends'] == $this->getDatabaseMap()->getClassName())
        {
            $children[] = $relation->getRightTable()->getClassName();
        }
    }
    return $children;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top