is possible overwriting a Doctrine model in Symfony?
I'm trying no change a "notnull" property, but i can get it..
In 'plugins/sfDoctrineGuardPlugin/config/doctrine/schema.yml':
sfGuardUser:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
username:
type: string(128)
notnull: true
unique: true
#...
And in 'config/doctrine/schema.yml':
sfGuardUser:
columns:
username:
type: string(128)
notnull: false
unique: true
Then "build-all-reload" but it doesn't change..
Any idea?
Javi
As coronatus said, you can overwrite schemas in Symfony 1.4, you should be able to do this in Symfony 1.3 also if you want to upgrade your project without removing all deprecated 1.2 stuff.
Related
I want to set Request Validator of API Gateway by serverless. I tried two different settings for the Request Validator. But, both methods have failed. I have summarized what I did, so please let me know if there is something wrong.
I write the API specification in swagger(OAS3.0). Therefore I tried to realize the setting of Request Validator using OAS extension. After I did sls deploy using below swagger.yaml and serverless.yml, None of the validate patterns described in x-amazon-apigateway-request-validators were added to the Request Validator options.
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validator.html
swagger.yaml is below:
openapi: 3.0.0
info:
description: xxx
version: '0.1'
title: xxx API
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true,
validateRequestParameters: false
except-body:
validateRequestBody: false,
validateRequestParameters: true
all:
validateRequestBody: true,
validateRequestParameters: true
tags:
- name: auth
description: xxx
paths:
/login:
post:
tags:
- auth
summary: xxx
description: ''
x-amazon-apigateway-request-validator: all
responses:
'200':
description: success
content:
application/json:
schema:
$ref: '#/components/schemas/AuthResponse'
'400':
description: fail
content:
application/json
'401':
description: fail
content:
application/json
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AuthRequest'
required: true
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
uri: "arn:aws:apigateway:ap-northeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:xxx-api-dev-login/invocations"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
contentHandling: "CONVERT_TO_TEXT"
type: "aws_proxy"
My serverless.yml is below:
resources:
Resources:
RestApi :
Type : AWS::ApiGateway::RestApi
Properties :
Body : ${file(./swagger.yaml)}
LoginApiToInvokeLambda:
Type: AWS::Lambda::Permission
DependsOn: LoginLambdaFunction
Properties:
FunctionName: xxx-ext-api-dev-login
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
I tried to realize the setting of Request Validator using AWS::ApiGateway::RequestValidator. After I did sls deploy using above swagger.yaml and below serverless.yml, the all described in RequestValidatorAll in severless.yml were added to the Request Validator options. But the default value of Request Validator was still NONE.
resources:
Resources:
RestApi :
Type : AWS::ApiGateway::RestApi
Properties :
Body : ${file(./swagger.yaml)}
LoginApiToInvokeLambda:
Type: AWS::Lambda::Permission
DependsOn: LoginLambdaFunction
Properties:
FunctionName: xxx-ext-api-dev-login
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
RequestValidatorAll:
Type: AWS::ApiGateway::RequestValidator
Properties:
Name: all
RestApiId:
Ref: RestApi
ValidateRequestBody: true
ValidateRequestParameters: true
You need to remove the commas in your YAML.
i.e
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true,
validateRequestParameters: false
except-body:
validateRequestBody: false,
validateRequestParameters: true
all:
validateRequestBody: true,
validateRequestParameters: true
should be
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true
validateRequestParameters: false
except-body:
validateRequestBody: false
validateRequestParameters: true
all:
validateRequestBody: true
validateRequestParameters: true
Once you do this the YAML will be valid and it should work.
I have a strange error in an admin module created by the admin generator:
My model has the following shema:
StmtcHelp:
columns:
module: { type: string(255) }
action: { type: string(255) }
content: { type: string(10000) }
translated: { type: boolean, notnull: true, default: false }
actAs:
Timestampable: ~
I18n:
fields: [content, translated]
My generator.yml:
generator:
class: sfDoctrineGenerator
param:
model_class: stmtcHelp
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: stmtc_help
with_doctrine_route: true
actions_base_class: sfActions
config:
actions:
_delete:
credentials: [is_super_admin]
_new:
credentials: [is_super_admin]
_create:
credentials: [is_super_admin]
fields: ~
list:
title: Inline Help
display: [ module, action, updated_at ]
filter:
display: [ module, action ]
form: ~
edit: ~
new: ~
Now I clear the cache and load the stmtc_help/index action, I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 's.content' in 'field list'.
Failing Query: "SELECT s.id AS s__id, s.module AS s__module, s.action AS s__action,
s.content AS s__content, s.translated AS s__translated, s.created_at AS s__created_at,
s.updated_at AS s__updated_at FROM stmtc_help s LIMIT 20"
It seems that Doctrine don't recognize my model as I18n.
But if I reload the page, the error disappear, all works fine.
Does anybody have had this kind of issue? What am I missing?
Thanks for any help!
I had exactly the same problem.
Your model_class parameter in generator.yml is set to stmtcHelp but your model name is StmtcHelp (the first letter is uppercase). Fix this one and check routing.yml for the same problem.
In my case I had my model misspelled only in routing.yml and it caused the same Column not found error.
if i build schema with Doctrine 1.2 for Symfony 1.4 i must add options: type, collate and charset, for example:
AlSupplier:
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
columns:
company_name:
type: string(255)
AlCountry:
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
columns:
country_name:
type: string(70)
AlSupplierCategory:
actAs:
NestedSet:
hasManyRoots: true
rootColumnName: root_id
Searchable:
fields: [category_keywords]
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
columns:
category_name:
type: string(200)
category_description:
type: text
category_keywords:
type: text
how can i set default options (type, collate, charset)? I don't want every time this write.
Just declare them at the top of the schema.yml file and they will be applied to every table:
options:
type: InnoDB
collate: utf8_unicode_ci
charset: utf8
Source: http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files#chapter_04_global_schema_information
I agree to Tom's solution.
Another option would be - if you want InnoDB to be used globally (e.g. also for plugins) - to define it in your ProjectConfiguration.php:
public function configureDoctrineConnection(Doctrine_Connection $connection)
{
$connection->setAttribute(Doctrine::ATTR_DEFAULT_TABLE_TYPE, 'InnoDB');
}
I have the follwing fixiture file:
Category:
webDev:
name: Development Web
webDesign:
name: Web Desing
Autres:
name: Autres
Post:
Post1:
Category: webDev
title: Ceci est un Test 1
content: TEST
Post2:
Category: webDesign
title: Ceci est un Test 2
content: TEST
Post3:
Category: Autres
title: Ceci est un Test 3
content: TEST
The problem is that webDev is not recognized and the id is not automatically seted.
I don't want to use like that:
Post1:
category_id: 1
title: Ceci est un Test 1
content: TEST
But I want to use the name of the webDev, webDesign or Autres categories names. Is working and I have no error when I run:
./symfony doctrine:build --all --no-confirmation --and-load
However, when I look in MySQL database instead of the category id I get NULL. Why? Where is the error?
Here is my schema.yml
Category:
tableName: categories
columns:
name: string(100)
Post:
tableName: posts
actAs:
Timestampable: ~
Sluggable:
fields: [title]
columns:
category_id: integer
title: string(100)
content: text
relations:
Category:
type: one
foreignType: many
local: id
foreign: id
According to your schema, the foreign key will bet set to post.id instead of post.category_id.
try local: category_id instead of local: id
I am using Propel as my DAL for my Symfony project. I can't seem to get my application to work across two or more databases.
Here's my schema.yml:
db1:
lkp_User:
pk_User: { type: integer, required: true, primaryKey: true, autoIncrement: true }
UserName: { type: varchar(45), required: true }
Password: longvarchar
_uniques:
Unique: [ UserName ]
db2:
tesco:
Id: { type: integer, required: true, primaryKey: true, autoIncrement: true }
Name: { type: varchar(45), required: true }
Description: longvarchar
And here's the databases.yml:
dev:
db1:
param:
classname: DebugPDO
test:
db1:
param:
classname: DebugPDO
all:
db1:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: 'mysql:dbname=bpodb;host=localhost' #where the db is located
username: root
password: #pass
encoding: utf8
persistent: true
pooling: true
db2:
class: sfPropelDatabase
param:
classname: PropelPDO
dsn: 'mysql:dbname=mystore2;host=localhost' #where the db is located
username: root
password: #pass
encoding: utf8
persistent: true
pooling: true
When I call php symfony propel-build-model, only db1 is generated, db2 is not.
Any idea how to fix this problem?
I got this issue working! The most important thing is you must name your schema according to %dbname%.schema.yml. In this way Symfony will be able to assign the ymls to the correct database.
Also when running the task you should specify the connection for example:
symfony propel:build-all-load --connection=my_connection
This worked for me, hope it helps.
You can also use Propel::getConnection('db2') to manually retrieve a connection.
Just have in mind that what you call "db1", "db2" are the connection names. You can have several connections to a same database with various login/permissions (like read only etc.).
It's very good for testing purpose: you can do it with the same connection name with a different database. No way to crash your production database with that :)