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
Related
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.
I'm trying to update a foreign key in processForm() and get this error.
It's a valid value
I can set values to a normal field without problem, I only get this error when I try to update foreign keys
This way i get the error:
$form->getObject()->setPriority(1);
This way i get no error but doesn't work too:
$form->getObject()->setPriorityId(1);
Schema:
schedule:
columns:
id:
primary: true
type: integer
notnull: true
autoincrement: true
sdate:
type: date
notnull: true
stime:
type: time
notnull: true
scope:
default: 1
type: boolean
schedule_count:
default: 0
type: integer(4)
reschedule_justify:
type: string
priority_id:
type: integer
notnull: true
schedule_type_id:
type: integer
notnull: true
pending_id:
default: NULL
type: integer
cancelled_id:
default: NULL
type: integer
scheduled_by:
type: integer
notnull: true
in_charge:
type: integer
notnull: true
so_id:
unique: true
type: integer
notnull: true
relations:
priority:
local: priority_id
foreign: id
scheduleType:
local: schedule_type_id
foreign: id
cancelled:
onDelete: SET NULL
local: cancelled_id
foreign: id
pending:
onDelete: SET NULL
local: pending_id
foreign: id
ScheduledBy:
class: employee
local: scheduled_by
foreign: id
InCharge:
class: employee
local: in_charge
foreign: id
soOrder:
local: so_id
foreign: id
Employees:
class: employee
refClass: schedule_employee
local: schedule_id
foreign: employee_id
priority:
actAs:
SoftDelete:
columns:
id:
primary: true
type: integer
notnull: true
autoincrement: true
name:
unique: true
type: string(255)
notnull: true
img:
type: string(255)
These are the main tables i'm using, I'm in schedule and trying to update priority
So, your task is to manually set a 'Priority' relation to a 'Schedule' object before saving it.
// PriorityForm
class ScheduleForm extends BaseScheduleForm
{
public function doSave($con = null)
{
//update object with form values (not necessary in your case, but will be if you need to
//use values that were in form
$this->updateObject();
$priority = Doctrine::getTable('Priority')->findOneById(1);
$this->getObject()->setPriority($priority);
return parent::doSave($con);
}
}
I'm editing a product and its current properties in a form with embedRelation('ProductProperty'). Everything is good so far. E/R diagram here http://d.pr/1N7R
However, now I want to split up the form and show attribute sets in different AJAX tabs according to its SetID. I still want to have a single 'Save' button, but it is not critical if I need to have multiple. How can I do this?
In my _form.php I'm iterating Sets but I can't seem to get the SetID for the ProductProperty form object. Am I going about this the wrong way?
I'm using symfony 1.4 and Doctrine 1.2. Here is my schema.yml
Product:
tableName: products
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [title]
canUpdate: true
columns:
id:
type: integer
primary: true
autoincrement: true
category_id:
type: integer
notnull: true
sku:
type: string(50)
notnull: true
title:
type: string(150)
notnull: true
relations:
Category:
foreignType: many
foreignAlias: Products
Property:
tableName: properties
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [description]
canUpdate: true
columns:
id:
type: integer
primary: true
autoincrement: true
set_id:
type: integer
notnull: true
description:
type: string(100)
notnull: true
relations:
Set:
foreignType: many
foreignAlias: Properties
Set:
tableName: sets
actAs:
Timestampable: ~
columns:
id:
type: integer
primary: true
autoincrement: true
title:
type: string(100)
notnull: true
ProductProperty:
tableName: product_properties
actAs:
Timestampable: ~
columns:
product_id:
type: integer
primary: true
property_id:
type: integer
primary: true
value:
type: text
notnull: true
relations:
Product:
alias: Product
foreignType: many
foreignAlias: ProductProperties
onDelete: cascade
Property:
alias: Property
foreignType: many
foreignAlias: PropertyProperties
onDelete: cascade
I managed to solve this with the help from dustin10 on the #symfony IRC channel (irc.freenode.net). In case anyone else need it, here is the solution:
We added a hidden field in my ProductPropertyForm with the SetID I was trying to retrieve in my form:
$this->setWidget('property_set_id', new sfWidgetFormInputHidden());
$this->setDefault('property_set_id', $this->getObject()->getProperty()->getSetId());
$this->setValidator('property_set_id', new sfValidatorString());
That way I could retrieve the value in my form with:
$eForm['property_set_id']->getValue()
I now have my form separated into multiple tabs with jQuery :) Again, thanks a lot to dustin10 for his help.
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
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