How to write "ON UPDATE" using orm file - sql

I am currently working on symfony2 project. I have one entity caller 'User'. For creating entity I am using orm file. I have created 'User' table using the following snippet.
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
email:
type: string
length: '50'
nullable: true
password:
type: text
nullable: true
name:
type: string
length: '50'
sex:
type: boolean
nullable: true
mobile:
type: bigint
nullable: true
landline:
type: bigint
nullable: true
dob:
type: date
nullable: true
Now I want to add two columns "CREATED ON" and "UPDATED ON" which stores the timestamp.
I want something like this
`Created on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Updated on` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,
Is there any way for doing this in orm.yml file?

You can use the Doctrine Extensions which implement a Timestampable behavior to Doctrine such as explain here:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md
But check which version you must use (depend on Doctrine), you can find this info in the README:
https://github.com/Atlantic18/DoctrineExtensions

Use https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md
This would be your additional attributes for the ORM
createdAt:
type: datetime
gedmo:
timestampable:
on: create
column: created_at
updatedAt:
type: datetime
gedmo:
timestampable:
on: update
column: updated_at

Related

How to change resource way , to support multiple future instances in Raml like city and airport?

/{ca}/{en}/{v1}:
uriParameters:
ca:
description: Country of users have to specify with two letter country code.
type: string
required: true
minLength: 2
maxLength: 2
en:
description: Language have to specified either English or French.
enum: [en,fr]
type: string
required: true
v1:
description: The version of the API need to be either v1 or v2.
enum: [v1,v2]
type: string
required: true

After pg_restore autoIncrements are reset to 0

I am using pg_dump/pg_restore to migrate data from one database to another, but some of tables have autoIncrements defined on the ids.
The autoIncrement is defined with:
.createTable('MyTable', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
When I try to create a new entry to the table using sequelize I get the error "SequelizeUniqueConstraintError: Validation error" as it is trying to set the id using autoIncrement starting at 0, instead of the next unused number. How can I fix this?

How to format a DELETE method in openapi 3.0.2?

I am having trouble figuring out a way to create a DELETE method for the POST method I just created in my API design. The post takes in a requestBody of the GlobalOrderSetupInfo, within that object there is another object that will be an array of different sessions that I want to add the GlobalOrderSetupInfo info to, in the delete method I need that same info deleted but you cannot have a delete method with a requestBody. How do I go about creating it?
Here is my post method:
'/api/globalorderdays':
post:
tags:
- Setup Global Order Days
summary: Allows user to add orderdays to multiple sessions
requestBody:
required: true
description: put text here
content:
application/json:
schema:
type: object
items:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
responses:
'201':
description: Created
'400':
description: Bad request
'401':
description: Unauthorized
components:
schemas:
GlobalOrderSetupInfo:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
AvailableHolidayList:
type: string
SelectedOrderHolidays:
type: string
example: "New Year's Day, President's Day, Memorial Day, Labor Day, Veterans Day, Thanksgiving Day, Chistmas Day"
SelectedHolidays:
type: string
example: "New Year's Day, President's Day, Memorial Day, Labor Day, Veterans Day, Thanksgiving Day, Chistmas Day"
OrderDays:
type: string
example: "01/01/2000"
NoOrderDays:
type: string
example: "01/01/2000"
AllSessionList:
uniqueItems: false
type: array
items:
$ref: '#/components/schemas/SessionInfoList'
SessionIdString:
type: string
example: "15"
SessionInfoList:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
SessionID:
type: integer
Name:
type: string
example: "Harbor"
Type:
type: string
GroupName:
type: string
example: "PHACTS"
IsChecked:
type: boolean
default: false
example: true/false
SetupID:
type: string
Typically your POST method creates a new entity, and returns the id of that entity. Then you might have additional routes to GET that entity by ID, update (PATCH) it, or DELETE it.
So in your example, the entry for DELETE might look like:
'/api/globalorderdays/{id}':
parameters:
- in: path
name: id
required: true
schema:
type: integer
get:
summary: Get orderdays by id
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
delete:
summary: Delete orderdays by id
responses:
'204':
description: Deleted
'404':
description: id not found
'401':
description: Unauthorized

How to create a table with foreign key constraint in Liquibase?

I am using yaml, but I guess it is almost the same as xml or json. I found that you can use addForeignKeyConstraint, but I want to add the constraint at table creation, not altering an existing table. How should I do that? Can I do something like this?
- changeSet:
id: create_questions
author: Author
changes:
- createTable:
tableName: questions
columns:
- column:
name: id
type: int
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: user_id
type: int
constraints:
foreignKey:
referencedColumnNames: id
referencedTableName: users
nullable: false
- column:
name: question
type: varchar(255)
constraints:
nullable: false
I never used the YAML format, but in an XML changelog you can do this:
<column name="user_id" type="int">
<constraints nullable="false"
foreignKeyName="fk_questions_author"
references="users(id)"/>
</column>
The equivalent YAML should be something like this:
- column:
name: user_id
type: int
constraints:
nullable: false
foreignKeyName: fk_questions_author
references: users(id)

symfony: stConfig::set('name', 'value') not working

I have the following configuration in defaults.yml:
poll_votes:
type: string
value: ''
name: 'Votes'
description: ''
editable: true
system: false
nullable: false
stConfig::get('poll_votes'); will return the correct value (which can be updated in the backend), but the value is not updated when calling stConfig::set('poll_votes', 'option1: 1 vote');
How can I set this values dynamically? Thank you.
stConfig? IIRC wasn't it sfConfig in Symfony 1?
Unless you are asking to change the contents of defaults.yml itself.