I create DateTime picker in Strapi with the required field validation but can't save. occurring following error.
apI Parametr
components: []
contentType: {name: "Events", description: "", connection: "default", collectionName: "events",…}
name: "Events"
description: ""
connection: "default"
collectionName: "events"
attributes: {title: {type: "string", required: true},…}
title: {type: "string", required: true}
created_by: {nature: "oneWay", target: "plugins::users-permissions.user", dominant: false, unique: false}
image: {type: "media", multiple: false, required: true}
seo_description: {type: "text"}
seo_title: {type: "string"}
description: {type: "richtext", required: true}
calendly_url: {type: "string"}
start_date: {type: "datetime", required: true}
type: "datetime"
required: true
end_date: {type: "datetime"}
PUT http://localhost:1337/content-type-builder/content-types/application::events.events 400 (Bad Request)```
I have a YAML file that has been written in the long syntax
children:
-
type: section
subtype: false
title: Top-wrapper
attributes: { }
children:
-
type: section
subtype: false
title: Second-wrapper
attributes: { }
children:
-
type: section
subtype: false
title: Header
attributes: { }
children:
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: section
subtype: false
title: Navigation
attributes: { }
children:
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: section
subtype: false
title: Showcase
attributes: { }
children:
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: section
subtype: false
title: Feature
attributes: { }
children:
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: section
subtype: false
title: Main-content
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 20
children:
-
type: section
subtype: false
title: Sidebar-left
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: position
subtype: false
title: Sidebar-left
attributes:
enabled: 1
key: sidebar-left
title: Sidebar-left
children: { }
-
type: block
subtype: false
title: Untitled
attributes:
size: 60
children:
-
type: section
subtype: false
title: Main
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: pagecontent
subtype: false
title: Pagecontent
attributes:
enabled: 1
children: { }
-
type: block
subtype: false
title: Untitled
attributes:
size: 20
children:
-
type: section
subtype: false
title: Sidebar-right
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: position
subtype: false
title: Sidebar-right
attributes:
enabled: 1
key: sidebar-right
title: Sidebar-right
children: { }
-
type: section
subtype: false
title: Subfeature
attributes: { }
children:
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: section
subtype: false
title: Footer
attributes: { }
children:
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: offcanvas
subtype: false
title: Offcanvas
attributes:
name: 'Offcanvas Section'
children: { }
-
type: atoms
subtype: false
title: Atoms
attributes:
name: 'Atoms Section'
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children: { }
I would like to convert it to use the shorthand syntax similar to this
layout:
1:
- top-wrapper 100:
header:
container:
- spacer
navigation:
container:
- [particle-logo 20, particle-menu 80]
showcase:
container:
- spacer
feature:
container:
- spacer
main:
container:
- system-messages
- pagecontent
footer:
container:
- spacer
debug:
container:
- spacer
offcanvas:
- particle-mobile-menu
I know YAML has certain rules about using the shorthand syntax, how can I use it?
The only way specified in the YAML specification to shorten YAML is by using anchors and references to these anchors (called aliases). Any other shortening would have to be done within the program that uses the data that YAML produces by semantically interpreting specific scalars.
The built-in anchor mechanism is normally used to have YAML documents share original data, e.g. if one mappings is referenced in two places in the hierarchical structure of mappings and sequences. That allows you to rewrite your input as:
children:
-
type: section
subtype: false
title: Top-wrapper
attributes: { }
children:
-
type: section
subtype: false
title: Second-wrapper
attributes: { }
children:
-
type: section
subtype: false
title: Header
attributes: { }
children: &cont00 # <- define anchor for the sequence node
-
type: container
subtype: false
title: Untitled
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: spacer
subtype: false
title: Spacer
attributes:
enabled: 1
children: { }
-
type: section
subtype: false
title: Navigation
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Showcase
attributes: { }
children: *cont00 # <- use the achored node
-
type: section
subtype: false
title: Feature
attributes: { }
children: *cont00 # <- use the anchored node
-
type: section
subtype: false
title: Main-content
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 20
children:
-
type: section
subtype: false
title: Sidebar-left
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: position
subtype: false
title: Sidebar-left
attributes:
enabled: 1
key: sidebar-left
title: Sidebar-left
children: { }
-
type: block
subtype: false
title: Untitled
attributes:
size: 60
children:
-
type: section
subtype: false
title: Main
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: pagecontent
subtype: false
title: Pagecontent
attributes:
enabled: 1
children: { }
-
type: block
subtype: false
title: Untitled
attributes:
size: 20
children:
-
type: section
subtype: false
title: Sidebar-right
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: position
subtype: false
title: Sidebar-right
attributes:
enabled: 1
key: sidebar-right
title: Sidebar-right
children: { }
-
type: section
subtype: false
title: Subfeature
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Footer
attributes: { }
children: *cont00
-
type: offcanvas
subtype: false
title: Offcanvas
attributes:
name: 'Offcanvas Section'
children: { }
-
type: atoms
subtype: false
title: Atoms
attributes:
name: 'Atoms Section'
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children: { }
children:
-
type: section
subtype: false
title: Top-wrapper
attributes: { }
children:
-
type: section
subtype: false
title: Second-wrapper
attributes: { }
children:
-
type: section
subtype: false
title: Header
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Navigation
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Showcase
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Feature
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Main-content
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 20
children:
-
type: section
subtype: false
title: Sidebar-left
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: position
subtype: false
title: Sidebar-left
attributes:
enabled: 1
key: sidebar-left
title: Sidebar-left
children: { }
-
type: block
subtype: false
title: Untitled
attributes:
size: 60
children:
-
type: section
subtype: false
title: Main
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: pagecontent
subtype: false
title: Pagecontent
attributes:
enabled: 1
children: { }
-
type: block
subtype: false
title: Untitled
attributes:
size: 20
children:
-
type: section
subtype: false
title: Sidebar-right
attributes: { }
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children:
-
type: block
subtype: false
title: Untitled
attributes:
size: 100
children:
-
type: position
subtype: false
title: Sidebar-right
attributes:
enabled: 1
key: sidebar-right
title: Sidebar-right
children: { }
-
type: section
subtype: false
title: Subfeature
attributes: { }
children: *cont00
-
type: section
subtype: false
title: Footer
attributes: { }
children: *cont00
-
type: offcanvas
subtype: false
title: Offcanvas
attributes:
name: 'Offcanvas Section'
children: { }
-
type: atoms
subtype: false
title: Atoms
attributes:
name: 'Atoms Section'
children:
-
type: grid
subtype: false
title: Untitled
attributes: { }
children: { }
I.e. you mark a node (and everything underneath) with a &+"unique id"
and you "insert" that same node with *+"unique id"
This is not a rewrite mechanism of the strings, such as the macros in C, and therefore there is no parametrising: the node structure must match exactly for this to work. When reading in such a YAML file you should end up with one object used in two locations.
If you want parametrisation, you would need to create some mechanism for loading (and writing) yourself, and that could further reduce the length of your file, but YAML would not be able to expand that as only your program would know how to do that.
When I try to execute php symfony doctrine:insert-sql , i get this error :
syntaxe error or access violation : 1072 key column 'id' doesn't existe in table
here is my schema.yml
Contact:
connection: doctrine
tableName: contact
columns:
id_contact:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: true
nom:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
fonction_organisme:
type: string(1000)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
categorie:
type: string(300)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
region:
type: string(1000)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
province:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
adresse:
type: string(1000)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
tel1:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
tel2:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
tel3:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
tel4:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
email:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
fax:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
ville:
type: string(50)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
journal:
type: string(2000)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
commentaire:
type: string(2000)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
fix:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
image:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
owner:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
relations:
Evenement:
local: id_contact
foreign: id_contact_event
type: many
Users :
class : User
refClass : OperationContact
foreignAlias : Contacts
Courrier:
connection: doctrine
tableName: courrier
columns:
num_serie:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: false
annee:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: false
num_c:
type: integer(2)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
exp:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
dest:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
state:
type: string(10)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
objet:
type: string(1000)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
image_c:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
date_recep:
type: date(25)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
date_env:
type: date(25)
fixed: false
unsigned: false
primary: false
notnull: false
autoincrement: false
owner_c:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
user_c:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
type_c:
type: string(500)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations :
Users :
class : User
refClass : OperationC
foreignAlias : Courriers
Evenement:
connection: doctrine
tableName: evenement
columns:
id_event:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: true
date:
type: date(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
action:
type: string(2000)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
id_contact_event:
type: integer(2)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations:
Contact:
local: id_contact_event
foreign: id_contact
type: one
OperationC:
connection: doctrine
tableName: operation_c
columns:
id_user:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: false
num_serie:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: false
operation_c:
type: string(2000)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
date_op_c:
type: date(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations :
User : { onDelete : CASCADE }
Courrier : { onDelete : CASCADE }
OperationContact:
connection: doctrine
tableName: operation_contact
columns:
id_contact:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: false
id_user:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: false
operation:
type: string(2000)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
date_op:
type: date(25)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
relations :
User : { onDelete : CASCADE }
Courrier : { onDelete : CASCADE }
User:
connection: doctrine
tableName: user
columns:
id_user:
type: integer(2)
fixed: false
unsigned: false
primary: true
autoincrement: true
nom_user:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
adresse_user:
type: string(2000)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
tel_user:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
login:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
password:
type: string(30)
fixed: false
unsigned: false
primary: false
notnull: true
autoincrement: false
I have two entities: User and Student. Following is the yaml schema:
ABC\UserBundle\Entity\User:
type: entity
table: abc_user
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
username: { type: string, length: 255, notnull: true, unique: true }
email: { type: string, length: 255, notnull: true, unique: true }
password: { type: string, length: 255, notnull: true }
enabled: { type: boolean }
ABC\UserBundle\Entity\Student:
type: entity
table: abc_student
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
first_name: { type: string, length: 255, notnull: true }
middle_name: { type: string, length: 255 }
last_name: { type: string, length: 255, notnull: true }
OnetoOne:
user:
targetEntity: ABC\UserBundle\Entity\User
My problem is that when I do "doctine:update:schema --dump-sql", user_id field is not added to the Student table and no relationship is created between the entities.
Yaml map is case-sensitive, use the proper name oneToOne for creating relations.
Your are missing the joinColumn option for the OneToOne association:
ABC\UserBundle\Entity\User:
type: entity
table: abc_user
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
username: { type: string, length: 255, notnull: true, unique: true }
email: { type: string, length: 255, notnull: true, unique: true }
password: { type: string, length: 255, notnull: true }
enabled: { type: boolean }
OnetoOne:
student:
targetEntity: ABC\UserBundle\Entity\Student
mappedBy: user
ABC\UserBundle\Entity\Student:
type: entity
table: abc_student
id:
id: { type: integer, generator: { strategy: AUTO } }
fields:
first_name: { type: string, length: 255, notnull: true }
middle_name: { type: string, length: 255 }
last_name: { type: string, length: 255, notnull: true }
OnetoOne:
user:
targetEntity: ABC\UserBundle\Entity\User
joinColumn:
name: user_id
referencedColumnName: id
I use symfony 1.4.10
I have next situation:
User can create "Ads" and he can create one "company". My part of schema:
Ads:
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [title]
canUpdate: false
connection: doctrine
tableName: ads
columns:
ad_id: { type: integer(4), primary: true, autoincrement: true, notnull: true }
user_id: {type: int(4) }
country: {type: string(255), notnull: true }
category_id: { type: int(4), notnull: true }
company: {type: string(255), notnull: true }
address: {type: string(255), notnull: true }
contact_person: {type: string(255), notnull: true }
phone: { type: string(50), notnull: true }
fax: { type: string(50) }
email: {type: string(255), notnull: true}
show_in_profile: { type: boolean,notnull: true , default: false }
title: {type: string(255), notnull: true }
content: {type: string(), notnull: true }
company: {type: string(255), notnull: true }
AGB: { type: boolean,notnull: true , default: false }
active: { type: boolean,notnull: true , default: 0 }
expires_at: { type: timestamp, notnull: true }
relations:
Owner: { onDelete: CASCADE, local: user_id, foreign: id, class: sfGuardUser }
Bookmark: { local: ad_id, foreign: user_id, class: sfGuardUser, refClass: Bookmarks }
Categories: { onDelete: CASCADE, local: ad_id, foreign: category_id }
Images: { local: ad_id, foreign: ad_id, type: many, class: Images }
Companies:
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [company]
canUpdate: false
connection: doctrine
tableName: companies
columns:
company_id: { type: integer(4), primary: true, notnull: true, autoincrement: true }
user_id: {type: int(4) }
category_id: {type: int(4), notnull: true }
company: {type: string(255), notnull: true }
address: {type: string(255), notnull: true }
contact_person: {type: string(255), notnull: true }
phone: { type: string(50), notnull: true }
fax: { type: string(50) }
email: {type: string(255), notnull: true}
url: { type: string(50) }
about: {type: string(), notnull: true}
country: {type: string(255), notnull: true}
active: { type: boolean, default: 0 }
has_company: { type: boolean, default: 1 }
relations:
Owner: { onDelete: CASCADE, local: user_id, foreign: id, class: sfGuardUser }
Images_companies: { local: company_id, foreign: company_id, type: many, class: Images_companies }
Categories: { onDelete: CASCADE, local: company_id, foreign: category_id }
sfGuardUserProfile:
connection: doctrine
tableName: sf_guard_user_profile
columns:
id: { type: integer(4), primary: true, autoincrement: true }
user_id: { type: integer(4), notnull: true }
salutation: { type: string(10), notnull: true }
first_name: { type: string(30), notnull: true }
last_name: { type: string(30), notnull: true }
country: { type: string(255), notnull: true }
postcode: { type: string(10) , notnull: true }
city: { type: string(255), notnull: true }
address: { type: string() , notnull: true }
phone: { type: string(50) }
email: { type: string(255), notnull: true }
validate: { type: string(17) }
banned: { type: boolean, default: 0 }
payed_until: { type: datetime, notnull: true}
relations:
User:
class: sfGuardUser
local: user_id
foreign: id
type: one
foreignType: one
foreignAlias: Profile
onDelete: CASCADE
So I need in each Ads of user put link to company of this user.So I do not know how to do it...
Part of routing:
ads:
url: /:sf_culture/account/ads/:action/*
param: { module: ads }
requirements:
sf_culture: (?:de|en|ru)
companies:
url: /:sf_culture/account/company/:action/*
param: { module: companies }
requirements:
sf_culture: (?:de|en|ru)
I think that it is possible in each ad to form a link to a company, but I do not know how I can get the id of company what I need.probably add relations between "Ads" and "Company"?Maybe there is another way to make a link to company?
p.s Sorry for ma bad English
that should be easy!
go to the form, and add this to the configure() method
public function configure() {
parent::configure();
unset(
$this['company_id'],
);
}
And when the form is saved, handle this in the action:
if ($this->form->isValid()) {
$user_id = // get user_id of authenticated user
$user = // get user obj
$company_id = $user->Companies->id;
$temp_ad = $this->form->getObject();
$ad->company_id = $company_id ;
$this->form->save();
}
Also, in your Ads model, the relation for Companies, foreign_id should just be id
In the companies model, put a unique index on user_id. That way a user can create only one company
Also, in companies model,
Owner: { onDelete: CASCADE, local: user_id, foreign: id, class: sfGuardUser, foreignAlias: Company }
Now in code, you can always do $user->Company to get the user's primary company
Create a reference to Company in the Ads model
Company: { onDelete: CASCADE, local: company_id, foreign: id, class: Company, foreignAlias: Ads }
Now you can get all Ads for a company as $company->Ads
or for a user $user->Company->Ads