Adrian
Nidziński
Student,
Politechnika
Łódzka
Temat: [sf 1.4] vjComment - problem z działaniem pluginu we...
Witam.Mam problem z pluginem vjComment.
Fragment pliku schema.yml:
Article:
actAs:
Timestampable: ~
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
slug:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
title:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
keywords:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
description:
type: string()
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
text:
type: clob(16777215)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
thumb:
type: string(100)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
image:
type: string(100)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Categories:
class: Category
refClass: CategoryHasArticle
local: article_id
foreign: category_id
foreignAlias: Articles
CategoryHasArticle:
local: id
foreign: article_id
type: many
Comment:
actAs:
Timestampable:
columns:
record_model:
type: string(255)
notnull: true
record_id:
type: integer
notnull: true
author_name:
type: string(255)
notnull: true
author_email:
type: string(255)
author_website:
type: string(255)
extra: link
body:
type: clob
notnull: true
is_delete:
type: boolean
default: false
edition_reason:
type: clob
reply:
type: integer
<?php if(vjComment::isGuardBindEnabled()): ?>
user_id:
type: integer(4)
notnull: false
<?php endif; ?>
indexes:
record_model_record_id:
fields: [record_model, record_id]
relations:
Comment: { local: reply, foreign: id }
<?php if(vjComment::isGuardBindEnabled()): ?>
sfGuardUser:
alias: User
local: user_id
type: one
foreign: id
foreignType: many
foreignAlias: Comments
<?php endif; ?>
CommentReport:
actAs:
Timestampable:
columns:
reason:
type: clob
notnull: true
referer:
type: string(255)
state:
type: enum
values: [valid, invalid, untreated]
default: untreated
id_comment:
type: integer
notnull: true
relations:
Comment: { onDelete: cascade, local: id_comment, foreign: id }
Chciałbym dodawać komentarze do wybranego artykułu. Moja tabela z artykułami nosi nazwę 'Article'.
W pliku actions.class.php mam metodę, odpowiedzialną za wyświetlanie artykułu o zadanym id.
public function executeShowArt(sfWebRequest $request) {
$q = Doctrine_Query::create()
->from('Article a')
->where('a.is_active = ?', 'true')
->andWhere('a.id = ?', $request->getParameter('id'))
->limit(1);
$this->arts = $q->fetchOne();
// vjCommentPlugin begin
$this->articles = Doctrine::getTable('Article')->find($request->getParameter('id'));
// vjCommentPlugin end
}
W templatce showArtSuccess.php próbuję wywołać plugin vjComment w poniższy sposób:
<?php include_component('comment', 'formComment', array('object' => $articles)) ?>
<?php include_component('comment', 'list', array('object' => $articles, 'i' => 0)) ?>
Niestety, otrzymuję "zwrotkę" postaci:
The "Comment" model has no "Article" relation.
Moja klasa bazowa z artykułem ma postać:
abstract class BaseArticle extends sfDoctrineRecord
{
public function setTableDefinition()
{
$this->setTableName('article');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
'length' => 4,
));
$this->hasColumn('slug', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 255,
));
$this->hasColumn('title', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 255,
));
$this->hasColumn('keywords', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('description', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('text', 'clob', 16777215, array(
'type' => 'clob',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 16777215,
));
$this->hasColumn('thumb', 'string', 100, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 100,
));
$this->hasColumn('image', 'string', 100, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 100,
));
$this->option('charset', 'utf8');
$this->option('type', 'InnoDB');
$this->option('collate', 'utf8_unicode_ci');
}
public function setUp()
{
parent::setUp();
$this->hasMany('Category as Categories', array(
'refClass' => 'CategoryHasArticle',
'local' => 'article_id',
'foreign' => 'category_id'));
$timestampable0 = new Doctrine_Template_Timestampable();
$this->actAs($timestampable0);
}
}
Klasa bazowa pluginu vjComment przedstawia się zaś następująco:
abstract class BaseComment extends sfDoctrineRecord
{
public function setTableDefinition()
{
$this->setTableName('comment');
$this->hasColumn('record_model', 'string', 255, array(
'type' => 'string',
'notnull' => true,
'length' => 255,
));
$this->hasColumn('record_id', 'integer', null, array(
'type' => 'integer',
'notnull' => true,
));
$this->hasColumn('author_name', 'string', 255, array(
'type' => 'string',
'notnull' => true,
'length' => 255,
));
$this->hasColumn('author_email', 'string', 255, array(
'type' => 'string',
'length' => 255,
));
$this->hasColumn('author_website', 'string', 255, array(
'type' => 'string',
'extra' => 'link',
'length' => 255,
));
$this->hasColumn('body', 'clob', null, array(
'type' => 'clob',
'notnull' => true,
));
$this->hasColumn('is_delete', 'boolean', null, array(
'type' => 'boolean',
'default' => false,
));
$this->hasColumn('edition_reason', 'clob', null, array(
'type' => 'clob',
));
$this->hasColumn('reply', 'integer', null, array(
'type' => 'integer',
));
$this->index('record_model_record_id', array(
'fields' =>
array(
0 => 'record_model',
1 => 'record_id',
),
));
$this->option('collate', 'utf8_unicode_ci');
$this->option('charset', 'utf8');
$this->option('type', 'InnoDB');
}
public function setUp()
{
parent::setUp();
$this->hasOne('Comment', array(
'local' => 'reply',
'foreign' => 'id'));
$this->hasMany('CommentReport', array(
'local' => 'id',
'foreign' => 'id_comment'));
$timestampable0 = new Doctrine_Template_Timestampable();
$this->actAs($timestampable0);
}
}
Czy ktoś jest mi w stanie pomóc? Gdzie szukać przyczyny błędu i jak go naprawić? Byłbym wdzięczny za wszelkie porady i sugestie.
Pozdrawiam.
Paweł Kubasiak Programista
Temat: [sf 1.4] vjComment - problem z działaniem pluginu we...
A przebudowałeś modele ? build-all
Adrian
Nidziński
Student,
Politechnika
Łódzka
Temat: [sf 1.4] vjComment - problem z działaniem pluginu we...
Dzięki za odzew. Okazało się, że przeoczyłem ważną kwestię w swoim pliku schema.yml. Przy deklaracji tabeli Article powinien się znaleźć zapis:
actAs:
Commentable:
Po dodaniu tego wpisu i przebudowaniu modeli wszystko gra.
