symfony doctrine query result and execute function - symfony1

I have this doctrine query in symfony. It returns a lot of rows when i run mysql code generated by this dql query in phpBB but when i run it in symfony and access its results with this code:
foreach ($this->courses as $course){
echo "<br>".$course->firstname;}
it returns only one name. Also when i try to get $course->title, this error appears
Unknown record property / related component "title" on "Students"
Query:
$q= Doctrine_Query::create()
->select('s.firstname,
s.middlename,
s.lastname,
p.program,
c.title,
pc.year')
->from('Students s')
->leftJoin('s.Programs p')
->leftJoin('p.Programcourses pc')
->leftJoin('pc.Courses c')
->where("idstudents = ?",2);
$this->courses=$q->execute();
schema.yml:
Courses:
connection: doctrine
tableName: courses
columns:
idcourses:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
title:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Programcourses:
local: idcourses
foreign: idcourses
type: many
Programcourses:
connection: doctrine
tableName: programcourses
columns:
idprogramcourses:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
idprograms:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
idcourses:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
year:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Courses:
local: idcourses
foreign: idcourses
type: one
Programs:
local: idprograms
foreign: idprograms
type: one
Programs:
connection: doctrine
tableName: programs
columns:
idprograms:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: false
program:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Programcourses:
local: idprograms
foreign: idprograms
type: many
Students:
local: idprograms
foreign: idprograms
type: many
Roles:
connection: doctrine
tableName: roles
columns:
idroles:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: false
role:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
Students:
connection: doctrine
tableName: students
columns:
idstudents:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
firstname:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
middlename:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
lastname:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
idprograms:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
session:
type: integer(4)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
username:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
password:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
email:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Programs:
local: idprograms
foreign: idprograms
type: one
Teachers:
connection: doctrine
tableName: teachers
columns:
idteachers:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
firstname:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
lastname:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
username:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
password:
type: string(45)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
email:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false

this is how i get it work...
$q= Doctrine_Query::create()
->select('s.firstname,
s.middlename,
s.lastname,
p.program,
c.title,
pc.year')
->from('Students s')
->leftJoin('s.Programs p')
->leftJoin('p.Programcourses pc')
->leftJoin('pc.Courses c')
->where("idstudents = ".$studentid);
//$this->query=$q->getSqlQuery();
$q->setHydrationMode(Doctrine_Core::HYDRATE_SCALAR);
$this->Student=$q->execute(array());
and in template
<?php foreach ($Student as $student): ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $student['c_title'] ?></td>
<td><?php echo $student['pc_year'] ?></td>
<td><?php echo $student['p_program'] ?></td>
</tr>
<?php endforeach; ?>

Your top node is the a Students object, because you use Students in the from()
Your error describe this
Also when i try to get $course->title, this error appears Unknown record property / related component "title" on "Students"
because you have a Students object, not a Courses one (where title belongs)
You are confusing yourself using
$this->courses=$q->execute();
$q= Doctrine_Query::create()
->select('s.firstname,
s.middlename,
s.lastname,
p.program,
c.title,
pc.year')
->from('Students s')
->leftJoin('s.Programs p')
->leftJoin('p.Programcourses pc')
->leftJoin('pc.Courses c')
->where("idstudents = ?", $studentid); // beware to SQL injection, use parameters
$this->Student=$q->fectchOne(); // as you are only retrieve one in your where clause
$this->Student=$q->execute()->getFirst(); // same
<tr>
<td><?php echo $i; /* not sure what this is for */ ?></td>
<td><?php echo $Student->Programs->Programcourses->Courses->title ?></td>
<td><?php echo $Student->Programs->Programcourses->year ?></td>
<td><?php echo $Student->Programs->program ?></td>
</tr>
If you want Courses to be the top, just go for something like:
$q= Doctrine_Query::create()
->select('s.firstname,
s.middlename,
s.lastname,
p.program,
c.title,
pc.year')
->from('Courses c')
->leftJoin('c.Programcourses pc')
->leftJoin('pc.Programs p')
->leftJoin('p.Students s')
->where("s.idstudents = ?", $studentid);

A few things:
Instead of $course->firstname and $course->title, you want $course->getFirstName() and $course->getTitle().
You should use singular names for your tables instead of plural, e.g. Course instead of Courses.
The convention in symfony is to use "id" for the primary key name instead of what you're doing.
Fix those problems - especially the first one - and your overall problem should go away.

Prepare query like this:
public function getAttendanceRecord($employeeId, $date) {
try {
$query = Doctrine_Query::create()
->from("attendanceRecord")
->where("employeeId = ?", $employeeId);
$records = $query->execute();
if (is_null($records[0]->getId())) {
return null;
} else {
return $records;
}
} catch (Exception $ex) {
throw new DaoException($ex->getMessage());
}
}
And try to get/print like this:
$attendanceOfTheDay = AttendanceDao::getAttendanceRecord($parameters['employeeId'], $parameters['date'])->toArray();
echo ' '; print_r($punchInTImeOfTheDay);
exit();

Related

need a help for the error Unknown record property / related component "permissions" on "sfGuardUser"

i am develping a project using symfony1.4.16 and Doctrine and for authentication i am using sfDoctrineGuardPlugin. In my localhost it was working fine. when i moved my project on a shared host i am getting this error(Unknown record property / related component "permissions" on "sfGuardUser") while login. when i search for this error in Google many people are recommending for delete all SFGuard Forms from lib/form/doctrine/base and reinstalling the plugin.How do i reinstall it on my sharedhost? what are the procedure should i take for uninstalling it on my sharedhost? whether i need to reinstall it in my localhost and upload it to my server or for should i use the command symfony plugin:uninstall sfDoctrineGuardPlugin or simply delete the files in lib/form/doctrine/base and upload it again to my server.The other modules which is not related to sfDoctrineGuardPlugin is working fine.Any one please help me...
More Information
when i login i am getting the error Unknown record property / related component "permissions" on "sfGuardUser" and when i refresh the page error is gone and i am redirecting to home page. In home page i have links for
add user,group,permission
edit user,group,permission
list user,group,permission
when i am trying to access add or edit portion i am getting error like this. List and delete portion is working fine
here i am attaching the screen shots of error and error log.
1.error page
2.error log
**
BaseSfGuardUser.class
**
<?php
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('SfGuardUser', 'doctrine');
/**
* BaseSfGuardUser
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* #property integer $id
* #property string $first_name
* #property string $last_name
* #property string $email_address
* #property string $username
* #property string $algorithm
* #property string $salt
* #property string $password
* #property integer $is_active
* #property integer $is_super_admin
* #property timestamp $last_login
* #property timestamp $created_at
* #property timestamp $updated_at
* #property Doctrine_Collection $SfGuardForgotPassword
* #property Doctrine_Collection $SfGuardRememberKey
* #property Doctrine_Collection $SfGuardUserGroup
* #property Doctrine_Collection $SfGuardUserPermission
*
* #method integer getId() Returns the current record's "id" value
* #method string getFirstName() Returns the current record's "first_name" value
* #method string getLastName() Returns the current record's "last_name" value
* #method string getEmailAddress() Returns the current record's "email_address" value
* #method string getUsername() Returns the current record's "username" value
* #method string getAlgorithm() Returns the current record's "algorithm" value
* #method string getSalt() Returns the current record's "salt" value
* #method string getPassword() Returns the current record's "password" value
* #method integer getIsActive() Returns the current record's "is_active" value
* #method integer getIsSuperAdmin() Returns the current record's "is_super_admin" value
* #method timestamp getLastLogin() Returns the current record's "last_login" value
* #method timestamp getCreatedAt() Returns the current record's "created_at" value
* #method timestamp getUpdatedAt() Returns the current record's "updated_at" value
* #method Doctrine_Collection getSfGuardForgotPassword() Returns the current record's "SfGuardForgotPassword" collection
* #method Doctrine_Collection getSfGuardRememberKey() Returns the current record's "SfGuardRememberKey" collection
* #method Doctrine_Collection getSfGuardUserGroup() Returns the current record's "SfGuardUserGroup" collection
* #method Doctrine_Collection getSfGuardUserPermission() Returns the current record's "SfGuardUserPermission" collection
* #method SfGuardUser setId() Sets the current record's "id" value
* #method SfGuardUser setFirstName() Sets the current record's "first_name" value
* #method SfGuardUser setLastName() Sets the current record's "last_name" value
* #method SfGuardUser setEmailAddress() Sets the current record's "email_address" value
* #method SfGuardUser setUsername() Sets the current record's "username" value
* #method SfGuardUser setAlgorithm() Sets the current record's "algorithm" value
* #method SfGuardUser setSalt() Sets the current record's "salt" value
* #method SfGuardUser setPassword() Sets the current record's "password" value
* #method SfGuardUser setIsActive() Sets the current record's "is_active" value
* #method SfGuardUser setIsSuperAdmin() Sets the current record's "is_super_admin" value
* #method SfGuardUser setLastLogin() Sets the current record's "last_login" value
* #method SfGuardUser setCreatedAt() Sets the current record's "created_at" value
* #method SfGuardUser setUpdatedAt() Sets the current record's "updated_at" value
* #method SfGuardUser setSfGuardForgotPassword() Sets the current record's "SfGuardForgotPassword" collection
* #method SfGuardUser setSfGuardRememberKey() Sets the current record's "SfGuardRememberKey" collection
* #method SfGuardUser setSfGuardUserGroup() Sets the current record's "SfGuardUserGroup" collection
* #method SfGuardUser setSfGuardUserPermission() Sets the current record's "SfGuardUserPermission" collection
*
* #package ticketsystem
* #subpackage model
* #author Your name here
* #version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
abstract class BaseSfGuardUser extends sfDoctrineRecord
{
public function setTableDefinition()
{
$this->setTableName('sf_guard_user');
$this->hasColumn('id', 'integer', 8, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
'length' => 8,
));
$this->hasColumn('first_name', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 255,
));
$this->hasColumn('last_name', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 255,
));
$this->hasColumn('email_address', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 255,
));
$this->hasColumn('username', 'string', 128, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 128,
));
$this->hasColumn('algorithm', 'string', 128, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => 'sha1',
'notnull' => true,
'autoincrement' => false,
'length' => 128,
));
$this->hasColumn('salt', 'string', 128, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 128,
));
$this->hasColumn('password', 'string', 128, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 128,
));
$this->hasColumn('is_active', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => '1',
'notnull' => false,
'autoincrement' => false,
'length' => 1,
));
$this->hasColumn('is_super_admin', 'integer', 1, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'default' => '0',
'notnull' => false,
'autoincrement' => false,
'length' => 1,
));
$this->hasColumn('last_login', 'timestamp', 25, array(
'type' => 'timestamp',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => false,
'autoincrement' => false,
'length' => 25,
));
$this->hasColumn('created_at', 'timestamp', 25, array(
'type' => 'timestamp',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 25,
));
$this->hasColumn('updated_at', 'timestamp', 25, array(
'type' => 'timestamp',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => 25,
));
}
public function setUp()
{
parent::setUp();
$this->hasMany('SfGuardForgotPassword', array(
'local' => 'id',
'foreign' => 'user_id',
'onDelete' => 'CASCADE'));
$this->hasMany('SfGuardRememberKey', array(
'local' => 'id',
'foreign' => 'user_id',
'onDelete' => 'CASCADE'));
$this->hasMany('SfGuardUserGroup', array(
'local' => 'id',
'foreign' => 'user_id',
'onDelete' => 'CASCADE'));
$this->hasMany('SfGuardUserPermission', array(
'local' => 'id',
'foreign' => 'user_id',
'onDelete' => 'CASCADE'));
}
}
**
BaseSfGuardUserForm.class
**
<?php
/**
* SfGuardUser form base class.
*
* #method SfGuardUser getObject() Returns the current form's model object
*
* #package ticketsystem
* #subpackage form
* #author Your name here
* #version SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
*/
abstract class BaseSfGuardUserForm extends BaseFormDoctrine
{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'first_name' => new sfWidgetFormInputText(),
'last_name' => new sfWidgetFormInputText(),
'email_address' => new sfWidgetFormInputText(),
'username' => new sfWidgetFormInputText(),
'algorithm' => new sfWidgetFormInputText(),
'salt' => new sfWidgetFormInputText(),
'password' => new sfWidgetFormInputText(),
'is_active' => new sfWidgetFormInputCheckbox(),
'is_super_admin' => new sfWidgetFormInputCheckbox(),
'last_login' => new sfWidgetFormDateTime(),
'created_at' => new sfWidgetFormDateTime(),
'updated_at' => new sfWidgetFormDateTime(),
'groups_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
'permissions_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission')),
));
$this->setValidators(array(
'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
'first_name' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
'last_name' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
'email_address' => new sfValidatorString(array('max_length' => 255)),
'username' => new sfValidatorString(array('max_length' => 128)),
'algorithm' => new sfValidatorString(array('max_length' => 128, 'required' => false)),
'salt' => new sfValidatorString(array('max_length' => 128, 'required' => false)),
'password' => new sfValidatorString(array('max_length' => 128, 'required' => false)),
'is_active' => new sfValidatorBoolean(array('required' => false)),
'is_super_admin' => new sfValidatorBoolean(array('required' => false)),
'last_login' => new sfValidatorDateTime(array('required' => false)),
'created_at' => new sfValidatorDateTime(),
'updated_at' => new sfValidatorDateTime(),
'groups_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)),
'permissions_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission', 'required' => false)),
));
$this->validatorSchema->setPostValidator(
new sfValidatorAnd(array(
new sfValidatorDoctrineUnique(array('model' => 'SfGuardUser', 'column' => array('email_address'))),
new sfValidatorDoctrineUnique(array('model' => 'SfGuardUser', 'column' => array('username'))),
))
);
$this->widgetSchema->setNameFormat('sf_guard_user[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
$this->setupInheritance();
parent::setup();
}
public function getModelName()
{
return 'SfGuardUser';
}
public function updateDefaultsFromObject()
{
parent::updateDefaultsFromObject();
if (isset($this->widgetSchema['groups_list']))
{
$this->setDefault('groups_list', $this->object->Groups->getPrimaryKeys());
}
if (isset($this->widgetSchema['permissions_list']))
{
$this->setDefault('permissions_list', $this->object->Permissions->getPrimaryKeys());
}
}
protected function doSave($con = null)
{
$this->saveGroupsList($con);
$this->savePermissionsList($con);
parent::doSave($con);
}
public function saveGroupsList($con = null)
{
if (!$this->isValid())
{
throw $this->getErrorSchema();
}
if (!isset($this->widgetSchema['groups_list']))
{
// somebody has unset this widget
return;
}
if (null === $con)
{
$con = $this->getConnection();
}
$existing = $this->object->Groups->getPrimaryKeys();
$values = $this->getValue('groups_list');
if (!is_array($values))
{
$values = array();
}
$unlink = array_diff($existing, $values);
if (count($unlink))
{
$this->object->unlink('Groups', array_values($unlink));
}
$link = array_diff($values, $existing);
if (count($link))
{
$this->object->link('Groups', array_values($link));
}
}
public function savePermissionsList($con = null)
{
if (!$this->isValid())
{
throw $this->getErrorSchema();
}
if (!isset($this->widgetSchema['permissions_list']))
{
// somebody has unset this widget
return;
}
if (null === $con)
{
$con = $this->getConnection();
}
$existing = $this->object->Permissions->getPrimaryKeys();
$values = $this->getValue('permissions_list');
if (!is_array($values))
{
$values = array();
}
$unlink = array_diff($existing, $values);
if (count($unlink))
{
$this->object->unlink('Permissions', array_values($unlink));
}
$link = array_diff($values, $existing);
if (count($link))
{
$this->object->link('Permissions', array_values($link));
}
}
}
here i am attaching my database schema too
**
schema.yml
**
SfGuardForgotPassword:
connection: doctrine
tableName: sf_guard_forgot_password
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
user_id:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
unique_key:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
expires_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardUser:
local: user_id
foreign: id
type: one
SfGuardGroup:
connection: doctrine
tableName: sf_guard_group
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
description:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardGroupPermission:
local: id
foreign: group_id
type: many
SfGuardUserGroup:
local: id
foreign: group_id
type: many
SfGuardGroupPermission:
connection: doctrine
tableName: sf_guard_group_permission
columns:
group_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
permission_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardGroup:
local: group_id
foreign: id
type: one
SfGuardPermission:
local: permission_id
foreign: id
type: one
SfGuardPermission:
connection: doctrine
tableName: sf_guard_permission
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
description:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardGroupPermission:
local: id
foreign: permission_id
type: many
SfGuardUserPermission:
local: id
foreign: permission_id
type: many
SfGuardRememberKey:
connection: doctrine
tableName: sf_guard_remember_key
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
user_id:
type: integer(8)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
remember_key:
type: string(32)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
ip_address:
type: string(50)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardUser:
local: user_id
foreign: id
type: one
SfGuardUser:
connection: doctrine
tableName: sf_guard_user
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
first_name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
last_name:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
email_address:
type: string(255)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
username:
type: string(128)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
algorithm:
type: string(128)
fixed: false
unsigned: false
primary: false
default: sha1
notnull: true
autoincrement: false
salt:
type: string(128)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
password:
type: string(128)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
is_active:
type: integer(1)
fixed: false
unsigned: false
primary: false
default: '1'
notnull: false
autoincrement: false
is_super_admin:
type: integer(1)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: false
autoincrement: false
last_login:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardForgotPassword:
local: id
foreign: user_id
type: many
SfGuardRememberKey:
local: id
foreign: user_id
type: many
SfGuardUserGroup:
local: id
foreign: user_id
type: many
SfGuardUserPermission:
local: id
foreign: user_id
type: many
SfGuardUserGroup:
connection: doctrine
tableName: sf_guard_user_group
columns:
user_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
group_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardGroup:
local: group_id
foreign: id
type: one
SfGuardUser:
local: user_id
foreign: id
type: one
SfGuardUserPermission:
connection: doctrine
tableName: sf_guard_user_permission
columns:
user_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
permission_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: false
created_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
updated_at:
type: timestamp(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
SfGuardPermission:
local: permission_id
foreign: id
type: one
SfGuardUser:
local: user_id
foreign: id
type: one
Thank you
clear symfony cache
remove base models of the sfDoctrineGuardPlugin:
lib/model/doctrine/sfDoctrineGuardPLugin/base/
rebuild your models using command line:
$ php symfony doctrine:build-model
rebuild your DB using command line
$ php symfony doctrine:build-sql
$ php symfony doctrine:insert-sql
During I server migration, I was seeing this same error for a different reason. The new server was running PHP 7.0, but I got it working by downgrading to PHP 5.6 (following the instructions here).

how to join eav table in table_method

I have the following schema.yml:
JosJeventsVevdetail:
connection: doctrine
tableName: jos_jevents_vevdetail
columns:
evdet_id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
rawdata:
type: string()
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
CustomField: { class: JosJeventsVevdetail, local: evdet_id, foreign: evdet_id, type: one, foreignType: many }
JosJevCustomfield:
connection: doctrine
tableName: jos_jev_customfields
columns:
id:
type: integer(4)
fixed: false
unsigned: false
primary: true
autoincrement: true
evdet_id:
type: integer(4)
fixed: false
unsigned: false
primary: false
default: '0'
notnull: true
autoincrement: false
name:
type: string(255)
fixed: false
unsigned: false
primary: false
default: ''
notnull: true
autoincrement: false
value:
type: string()
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
I.e. there are many name/value pairs that are matched with a single record in JosJeventsVevdetail.
I'm trying to flatten this with a table method ( and some other tables) like this:
return $q->
innerJoin("$rootAlias.Event e")->
innerJoin("e.EventDetail ed")->
innerJoin("ed.CustomField cf")->
innerJoin("$rootAlias.JoomlaUser u")->
innerJoin("u.Person p")->
innerJoin("$rootAlias.Status s")->
innerJoin("$rootAlias.RsvpType rt")->
addWhere("cf.name=?",'preconExams')-> //this removed works,but query wrong
addSelect("$rootAlias.*, e.*, ed.*, s.*, rt.*, u.*, p.*, cf.*");
but I get an error message "Unknown column name". When I remove cf.name='preconExams', the query runs, but jos_jev_customfields is not joined in the query.
Is there anything wrong with the schema?
what is wrong is the class of your relation. It shoud be JosJevCustomfield and you've put JosJeventsVevdetail ;-) . JosJeventsVevdetail has no column name, hence the error.

schema.yml using sfDoctrineGuardPlugin

I'm building a schema.yml and I'm trying to add foreign key constraints to the table sf_guard_user.
But, when I do doctrine:insert-sql (edit: doctrine:build --all), the links between my tables and sf_guard_user are not there ! Am I missing something ?
I'm using mysql (InnoDB) and Symfony 1.4
Here's a sample of my schema.yml :
Author:
connection: doctrine
tableName: ec_author
actAs:
Sluggable:
fields: [name]
unique: true
canUpdate: false
columns:
sf_guard_user_id:
type: integer
fixed: false
unsigned: false
primary: true
autoincrement: false
name:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
contents:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
User:
class: sfGuardUser
foreignType: one
local: sf_guard_user_id
foreign: id
There are no links to sfGuardUser, even though they are described in schema.yml :
This one works:
Author:
connection: doctrine
tableName: ec_author
actAs:
Sluggable:
fields: [name]
unique: true
canUpdate: false
columns:
sf_guard_user_id:
type: integer
fixed: false
unsigned: false
primary: false
autoincrement: false
name:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
contents:
type: string()
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
User:
class: sfGuardUser
foreignType: one
local: sf_guard_user_id
foreign: id
foreignAlias: author
sf_guard_user_id is a foreign key, then it can't be a primary key. so I changed
primary: true to primary: false.
You should be rebuilding the models and sql as well. Try running:
symfony doctrine:build --all
This will clobber all existing data. If you don't want that, you'll have to write a migration.
The Class name needs to be the same name as you specified when opening the corresponding table in your schema file.
So, for example, you are using:
relations:
User:
class: sfGuardUser
foreignType: one
The class name here must match the declaration of the sfGuardUser table. Just make sure they are the same. Sometimes, it can be declared as sf_guard_user.
If that is fine, you can try adding a few more definitions to your Relations entry:
relations:
User:
class: sfGuardUser
foreignType: one
local: sf_guard_user_id
foreign: sf_guard_user_id

symfony : Problem with the method 'embedRelation'

I have two classes with a relation one-to-many. And I want to make a nested form to enter an object and some of others which are linked to it.
But when I save the form, the key wich references my main class isn't update with the key of main class. However the other keys are created.
My schema :
Enfant:
connection: doctrine
tableName: enfant
columns:
id:
type: integer(2)
fixed: false
unsigned: true
primary: true
autoincrement: true
nudparent:
type: string(20)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Locataire:
local: nudparent
foreign: nud
type: one
Locataire:
connection: doctrine
tableName: locataire
columns:
nud:
type: string(20)
fixed: false
unsigned: false
primary: true
autoincrement: false
nbenfants:
type: integer(1)
fixed: false
unsigned: true
primary: false
notnull: false
autoincrement: false
relations:
Bail:
local: nud
foreign: locataire
type: many
Enfant:
local: nud
foreign: nudparent
type: many
Refus:
local: nud
foreign: nud
type: many
And making form :
$subForm = new sfForm();
for ($i = 0; $i < 2; $i++)
{
$enfant = new Enfant();
$enfant->Locataire = $this->getObject();
$form = new EnfantForm($enfant);
$subForm->embedForm($i, $form);
}
$this->embedForm('new', $subForm);
You need to use embedRelation. You can find more information and examples here: http://prendreuncafe.com/blog/post/2009/11/29/Embedding-Relations-in-Forms-with-Symfony-1.3-and-Doctrine

Join query in doctrine symfony

I have two tables userdetails and blog question The schema is
UserDetails:
connection: doctrine
tableName: user_details
columns:
id:
type: integer(8)
fixed: false
name:
type: string(255)
fixed: false
BlogQuestion:
connection: doctrine
tableName: blog_question
columns:
question_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
blog_id:
type: integer(8)
fixed: false
user_id:
type: integer(8)
fixed: false
question_title:
type: string(255)
I am using one join query for retrieving all the questions and user details from this two tables My join query is
$q = Doctrine_Query::create()
->select('*')
->from('BlogQuestion u')
->leftJoin('u.UserDetails p');
$q->execute();
But it is showing this error Unknown relation alias UserDetails
Pls anybody help me
Thanks in advance
why have you not set up a relationship in your doctrine?
UserDetails:
connection: doctrine
tableName: user_details
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
BlogQuestion:
connection: doctrine
tableName: blog_question
columns:
question_id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
blog_id:
type: integer(8)
fixed: false
user_id:
type: integer(8)
fixed: false
question_title:
type: string(255)
relations:
UserDetails:
local: user_id
there is nothing in your yml to tell doctrine what it should be linking on when you left join. I have just build this myself and it does work

Resources