MySQL Views verwenden mit Propel und Symfony
Geschrieben von skaldrom am 13. November 2006
Symfony, das PHP-Framework ist genial. Will man allerdings die Datenbank-Views verwenden, geht das nicht so direkt.
Damit die Propel orm-Klassen generiert werden, muss im config/schema.yml die Struktur so definiert werden, dass sie nicht direkt in die Datenbank abgespitzt wird:
m_my_view:
_attributes: { phpName: ModulCompleteView, skipSql: true}
post_id: {type: integer}
post_title: {type: varchar, size: 255}
post_content: {type: longvarchar}
comment_id: {type: integer}
comment_content:{type: longvarchar}
_attributes: { phpName: ModulCompleteView, skipSql: true}
post_id: {type: integer}
post_title: {type: varchar, size: 255}
post_content: {type: longvarchar}
comment_id: {type: integer}
comment_content:{type: longvarchar}
Damit die View bei symfony propel-insert-sql erstellt wird, sollte eine Datei im gleichen Verzeichnis erstellt werden in dem auch lib.model.schema.swl ist (normalerweise /data/sql). Wir nennen sie my-view.sql:
CREATE OR REPLACE view m_my_view as
SELECT
post.id as post_id,
post.title as post_title,
post.content as post_content,
comment.id as comment_id,
comment.content as comment_content
FROM
post, comment
WHERE
comment.post_id=post.id
SELECT
post.id as post_id,
post.title as post_title,
post.content as post_content,
comment.id as comment_id,
comment.content as comment_content
FROM
post, comment
WHERE
comment.post_id=post.id
Und nun nur noch die Datei sqldb.map ergänzen:
my-view.sql=DB-VERBINDUNG
und nun sollts funzen.









