I'm looking to create fixtures file for the following schema (Movies library):
VodProgram:
actAs: { Timestampable: ~ }
columns:
title: { type: string(255), notnull: true }
year: { type: smallint }
...
relations:
VodPersons:
class: VodPerson
refClass: VodCasting
local: program_id
foreign: person_id
foreignAlias: VodPrograms
VodPerson:
columns:
name: { type: string(255), notnull: true }
VodCasting:
columns:
program_id: { type: integer, primary: true }
person_id: { type: integer, primary: true }
role: { type: string(255) }
rank: { type: smallint }
relations:
VodProgram: { onDelete: CASCADE, local: program_id, foreign: id }
VodPerson: { onDelete: CASCADE, local: person_id, foreign: id }
My problem is creating fixtures file with the "role" and "rank" fields present in the VodCasting table.
Here is my actual fixtures:
VodPerson:
kosinski:
name: Joseph Kosinski
VodProgram:
tron:
VodPersons: [kosinski] # where to put the role and rank infos ?
title: Tron
year: 2010
I tried something like :
VodProgram:
tron:
VodPersons:
kosinski:
rank: 1
title: Tron
...
with no luck.
Any suggestions?
Thanks.
Have you tried something like that :
VodPerson:
kosinski:
name: Joseph Kosinski
VodProgram:
tron:
title: Tron
year: 2010
VodCasting:
tron_kosinski:
role: 'Director'
rank: 1
VodPerson: kosinski
VodProgram: tron
Related
In Symfony 1.4, Doctrine I have this snippet from schema.yml
Attendance:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
user_id: { type: integer(4) }
relations:
JoomlaUser: { class: JosUser, local: user_id, foreignAlias: AttendanceList }
and
JosUser:
tableName: jos_users
columns:
id: { type: integer(4), primary: true, autoincrement: true }
relations:
AttendanceList: { class: Attendance, local: id, foreign: user_id }
What is the most efficient way to determine from JosUser that there are no Attendance records. I tried model/doctrine/JosUser.class.php
count($this->getAttendanceList())
but this returns a Doctrine Record with all fields empty but user_id
Schema :
JosUser:
tableName: jos_users
columns:
id: { type: integer(4), primary: true, autoincrement: true }
relations:
AttendanceList: { type: many, class: Attendance, local: id, foreign: user_id }
With type: many, getAttendanceList() should return a Doctrine_Collection (see the JosUser base class in lib/model/doctrine/base/BaseJosUser.class.php), then you can use
$this->getAttendanceList()->count()
I have a registration form that includes sfRegistration and sfProfile, which after completion, get's redirected to another form - to determine the user's corporation and is a seperate module. The sfProfile includes a field from the corporation module... the corporate_id. But since the corporate_id is not part of the profile, it does not get included at registration time. Here's the question, after completion of the corporation module, what is the best way to update the user's profile with the corporate_id of the newly completed corporation module? I tried this:
public function postSave()
{
$corpId = $this->form->getId();
$logged_user_id = sfContext::getInstance()->getUser()->getId();
Doctrine_Query::create()
->update('sf_guard_user_profile p')
->set('p.corporate_id', $corpId)
->where('p.user_id' == $logged_user_id )
->execute();
}
placed into the action of the company module, but it is not updating the profile with the company_id.
Suggestions?
UPDATE - per request, here is the information requested: (my >>lib>form>>doctrine>>CorporationForm.class.php is empty... I was trying my functions in the actions class... which may be the issue). Just to clarify, I just need to update the user's profile with the newly created corporate_id after the user completes the corporation module.
And my schema:
sfGuardUser:
actAs: [Timestampable]
columns:
first_name: string(255)
last_name: string(255)
email_address:
type: string(255)
notnull: true
unique: true
username:
type: string(128)
notnull: true
unique: true
algorithm:
type: string(128)
default: sha1
notnull: true
salt: string(128)
password: string(128)
is_active:
type: boolean
default: 1
is_super_admin:
type: boolean
default: false
last_login:
type: timestamp
indexes:
is_active_idx:
fields: [is_active]
relations:
Groups:
class: sfGuardGroup
local: user_id
foreign: group_id
refClass: sfGuardUserGroup
foreignAlias: Users
Permissions:
class: sfGuardPermission
local: user_id
foreign: permission_id
refClass: sfGuardUserPermission
foreignAlias: Users
sfGuardUserProfile:
actAs: { Timestampable: ~ }
columns:
id: { type: integer, primary: true, notnull: true, autoincrement: true, unique: true }
user_id: { type: integer }
corporate_id: { type: integer }
type_id: { type: integer, notnull: true }
prefix_id: { type: integer }
middle_name: { type: string(55) }
suffix_id: { type: integer }
phone: { type: string(55), notnull: true }
home_address_line_one: { type: string }
home_address_line_two: { type: string }
home_city: { type: string }
state_id: { type: integer }
home_zip: { type: integer }
relations:
User: { class: sfGuardUser, local: user_id, foreign: id, type: one, foreignType: one, foreignAlias: Profile }
Type: { local: type_id, foreign: id, type: one, foreignAlias: Types }
Prefix: { local: prefix_id, foreign: id, type: one, foreignAlias: Prefixs }
Suffix: { local: suffix_id, foreign: id, type: one, foreignAlias: Suffixs }
State: { local: state_id, foreign: id, foreignAlias: States }
Corporation: { local: corporate_id, foreign: id, foreignAlias: Corporations }
Corporation:
columns:
id: { type: integer, primary: true, notnull: true, autoincrement: true, unique: true }
user_id: { type: integer }
name: { type: string(55), notnull: true }
address_line1: { type: string(255), notnull: true }
address_line2: { type: string(255), notnull: true }
city: { type: string(25), notnull: true }
state_id: { type: integer, notnull: true }
zip: { type: string(25), notnull: true }
phone: { type: string(25), notnull: true }
email: { type: string(100), notnull: true }
website: { type: string(100) }
logo: { type: string(255) }
relations:
User: { class: sfGuardUser, local: user_id, foreign: id, foreignAlias: Users }
In your form:
public function doUpdateObject($values)
{
parent::doUpdateObject($values);
$this->getObject()->setCorporateId(your value);
}
For example
//apps/frontend/yourmodule/action.class.php
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
$corporation = $form->save();
$user_id=$this->getUser()->getGuardUser()->getId();
$profile = Doctrine_Core::getTable('sfGuardUserProfile')->findOneByUserId($user_id);
$profile->setCorporateId('your value');
Don't forget the ->save();
public function setId()
{
$user_id = $this->getUser()->getGuardUser()->getId();
$corp_id = 1;
$user_profile = Doctrine_Core::getTable('sfGuardUserProfile')->findOneByUserId($user_id);
$user_profile->setCorporateId($corp_id)->save();
}
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid())
{
self::setId();
$corporation = $form->save();
$this->redirect('dashboard/index');
}
}
I've got the following schema.yml file, but it's just not working correctly. Can anyone point me in the right direction please?
ClientPaymentService:
actAs: { Timestampable: ~ }
columns:
clientId: integer
name: { type: string(100), notnull: true, unique: true }
paymentServiceId: integer
config: { type: string(4096), notnull: true }
cardFormatId: integer
relations:
Client:
local: clientId
foreign: id
type: many
foreignType: one
foreignAlias: Client
PaymentService:
local: paymentServiceId
foreign: id
type: many
foreignType: one
foreignAlias: ClientPaymentService
CardFormat:
local: cardFormatId
foreign: id
type: many
foreignType: one
foreignAlias: ClientCardFormats
CountryCode:
class: CountryCode
refClass: ClientPaymentServiceCountryCode
foreign: id # country_code_id also doesn't work
local: id
ClientPaymentServiceCountryCode:
columns:
client_payment_service_id:
type: integer
primary: true
country_code_id:
type: integer
primary: true
relations:
ClientPaymentService:
local: client_payment_service_id
foreign: id
foreignAlias: ClientPaymentServiceCountryCodes
CountryCode:
local: country_code_id
foreign: id
foreignAlias: ClientPaymentServiceCountryCodes
CountryCode:
actAs: { Timestampable: ~ }
columns:
name: { type: string(100), notnull: true, unique: true }
code: { type: string(10), notnull: true, unique: true }
relations:
ClientPaymentService:
class: ClientPaymentService
refClass: ClientPaymentServiceCountryCode
local: id
foreign: id # client_payment_service_id also doesn't work
I receive the following error when trying to save something in the admin area:
Unknown record property / related component "id" on "ClientPaymentServiceCountryCode"
Thanks
Try this association:
ClientPaymentService:
.....
CountryCode:
class: CountryCode
refClass: ClientPaymentServiceCountryCode
foreign: country_code_id # country_code_id also doesn't work
local: client_payment_service_id # you must define both directions
ClientPaymentServiceCountryCode:
columns:
client_payment_service_id:
type: integer
primary: true
country_code_id:
type: integer
primary: true
// you not have to define relations here
CountryCode:
....
ClientPaymentService:
class: ClientPaymentService
refClass: ClientPaymentServiceCountryCode
local: country_code_id
foreign: client_payment_service_id
I have just follow documentation :
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/ru#relationships:join-table-associations:many-to-many
I'm getting a weird error in symfony 1.4 with doctrine 1.2. My schemas seem to be normal. But whenever I execute the doctrine:build --all --no-confirmation --and-load task, it would output the error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'default_edition_id' cannot be null. If I set notnull to false for the default_edition_id field, it would actually just be null. Can anyone help me out on what I may be missing?
Here is my schema file (chapter.yml):
Chapter:
actAs:
Timestampable: ~
Versionable:
versionColumn: version
className: %CLASS%Version
SoftDelete: ~
columns:
name: string
chapter_number: { type: integer, notnull: true }
series_id: { type: integer, notnull: true }
default_edition_id: { type: integer, notnull: true }
disabled:
type: enum
values: [1, 0]
default: 0
notnull: true
relations:
DefaultEdition:
local: default_edition_id
class: Edition
foreign: id
foreignAlias: DefaultChapter
foreignType: one
type: one
# onDelete: CASCADE
Series:
local: series_id
foreign: id
onDelete: CASCADE
Editions:
type: many
class: Edition
local: id
foreign: chapter_id
and my edition schema (edition.yml):
Edition:
actAs:
Timestampable: ~
Sluggable:
fields: [name]
Versionable:
versionColumn: version
className: %CLASS%Version
SoftDelete: ~
columns:
name: string
completed_reads: { type: integer, notnull: true, default: 0}
views: { type: integer, notnull: true, default: 0 }
language_id: { type: integer, notnull: true }
chapter_id: { type: integer, notnull: true }
disabled:
type: enum
values: [1, 0]
default: 0
notnull: true
relations:
Pages:
type: many
class: Page
local: id
foreign: edition_id
Language:
local: language_id
foreign: id
type: one
onDelete: CASCADE
Chapter:
local: chapter_id
foreign: id
onDelete: CASCADE
Fixtures:
Chapter:
bakuman_chapter:
Series: bakuman
chapter_number: 86
DefaultEdition: edition_1
bakuman_chapter2:
Series: bakuman
DefaultEdition: edition_2
chapter_number: 90
Edition:
edition_1:
name: edition 1
Chapter: bakuman_chapter
ScanlationGroup: [group_1, group_2, group_3]
Language: english
edition_2:
name: edition 2
Chapter: bakuman_chapter2
ScanlationGroup: [group_4]
Language: japanese
edition_2_2:
name: edition 2_2
Chapter: bakuman_chapter2
ScanlationGroup: [group_4, group_2]
Language: english
"If I set notnull to false for the default_edition_id field, it would actually just be null". In this sentence, was does "it" refer to? Notnull means that the value 'null' is acceptable for this field, not that its value will always be null, if this was what you meant.
I'm setting up my first symfony project, and am having trouble with the schema. I'm not sure if I'm going about it the right way.
I'm having a problem with two of my classes. I have Clients, which can have many Contacts, one of the contacts needs to be selected as the invoice contact. This is my schema:
NativeClient:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
address: { type: string(255) }
postcode: { type: string(9) }
tel: { type: string(50) }
fax: { type: string(50) }
website: { type: string(255) }
client_status_id: { type: integer, notnull: true, default: 0 }
priority: { type: boolean, notnull: true, default: 0 }
invoice_contact_id: { type: integer }
invoice_method_id: { type: integer }
relations:
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
NativeClientStatus: { local: client_status_id, foreign: id, foreignAlias: NativeContacts }
NativeInvoiceMethod: { local: invoice_method_id, foreign: id, foreignAlias: NativeClientStatuses }
NativeContact:
actAs: { Timestampable: ~ }
columns:
client_id: { type: integer, notnull: true }
name: { type: string(255), notnull: true }
position: { type: string(255) }
tel: { type: string(50), notnull: true }
mobile: { type: string(50) }
email: { type: string(255) }
relations:
NativeClient: { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients }
NativeClientStatus:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
NativeInvoiceMethod:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
If i remove the following line (and associated fixtures) it works, otherwise I get a segmentation fault.
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
Could it be getting in a loop? Trying to reference the Client and the Contact over and over? Any help would be greatly appreciated! Thanks!
Darren
Old question I know, but heres a follow up solution. Sometimes Doctrine will throw this error for seemingly no reason whatsoever. Im sure there is an underlying reason, but we dont all have time to debug the entire Doctrine source.
Try specifying --env=[your env], and it may just work - has for me.
Darren, it seems like you're defining the relationship at both ends while using conflicting criteria...
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
...relationship is between "invoice_contact_id" and undeclared "id" PK in NativeContact.
NativeClient: { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients }
... same relationship is between "client_id" and undeclared "id" PK in NativeClient.
I personally only define these in one end and let Doctrine handle the rest, but it depends on what you're trying to achieve here. If ONE client HAS MANY contacts, you could drop the second declaration and define the relationship in the clients table only and add "type: many, foreignType: one" to state that it's a one-to-many relationship.