Date not display in responce (symfony3, doctrine) - symfony

My controller:
class LoggingController extends Controller
{
public function getLogAction()
{
$result = $this->getDoctrine()->getRepository(ChangeLog::class)->findAll();
if ($result === NULL) {
return new View("Log not found", Response::HTTP_NOT_FOUND);
}
return new View($result,Response::HTTP_OK);
}
}
My doctrine orm.yml:
AppBundle\Entity\ChangeLog:
type: entity
table: null
repositoryClass: AppBundle\Repository\ChangeLogRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
date:
type: datetime
#...and other
When I try to display my records from table, I receive this in date (date is empty):
But in my table in db everything are normal:
What is wrong? All another data displays normally...
I use FosRestBundle for displaying data in JSON format.

Related

How to get nested data using AppSync generated query?

I have the following graphql schema:
type Post
#model {
id: ID!
title: String!
content: String!
comments: [Comment] #hasMany(indexName: "byPost", fields: ["id"])
}
type Comment
#model {
id: ID!
message: String
post: Post #belongsTo(fields: ["postID"])
postID: ID #index(name: "byPost")
}
AppSync generated the following query for this schema:
export const listPosts = /* GraphQL */ `
query ListPosts(
$filter: ModelPostFilterInput
$limit: Int
$nextToken: String
) {
listPosts(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
title
content
comments {
nextToken
}
createdAt
updatedAt
}
nextToken
}
}
`;
Now when I use it like this:
const postData = await API.graphql({
query: listPosts,
});
There are no comments in result, is returns comments: { nextToken: null } as part of a post, but there are comments, associated with the post in the database.
How can I get nested data in this case?

symfony elastica bundle Exception when property of entity relation contain null

I have a item entity, stock entity and color entity
Item has oneToMany stocks and stock have ManytoOne association with color
now I am mapping item entity and stocks with elastic search. I am mapping stocks as nested of item
but it gives an error when color_id is null in stock table, how I can solve this exception
item:
mappings:
id: { type: integer }
title: { index: analyzed, analyzer: autocomplete, search_analyzer: autocomplete }
description: { index: analyzed, analyzer: simple }
stock:
type: nested
include_in_root: true
properties:
id: { type: integer }
color: { type: object}
Type error: Return value of AppBundle\Entity\Stock::getColor() must be an instance of AppBundle\Entity\Color, null returned
I am stuck from couple of days, if anyone have idea please share

AppSync batch insert to DynamoDB fails and returns null

I have the following resolver settings:
#set($questions = [])
#foreach($item in ${ctx.args.questions})
#set($item.id = $util.dynamodb.toDynamoDBJson($util.autoId()))
$util.qr($questions.add($util.dynamodb.toMapValues($item)))
#end
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables" : {
"QuestionTable": $utils.toJson($questions)
}
}
And the following GraphQL schema:
input CreateQuestionInput {
text: String
sectionId: ID!
}
input CreateScoreInput {
score: Int!
questionId: ID!
userId: ID!
}
input CreateSectionInput {
title: String
subSection: String
}
input DeleteQuestionInput {
id: ID!
}
input DeleteScoreInput {
id: ID!
}
input DeleteSectionInput {
id: ID!
}
type Mutation {
...
createQuestion(input: CreateQuestionInput!): Question
batchCreateQuestion(questions: [CreateQuestionInput]!): [Question]
}
type Query {
getSection(id: ID!): Section
listSections(filter: TableSectionFilterInput, limit: Int, nextToken: String): SectionConnection
getScore(id: ID!): Score
listScores(filter: TableScoreFilterInput, limit: Int, nextToken: String): ScoreConnection
getQuestion(id: ID!): Question
listQuestions(filter: TableQuestionFilterInput, limit: Int, nextToken: String): QuestionConnection
}
type Question {
id: ID!
text: String
sectionId: ID!
}
type QuestionConnection {
items: [Question]
nextToken: String
}
type Schema {
query: Query
}
type Score {
id: ID!
score: Int!
questionId: ID!
userId: ID!
}
type ScoreConnection {
items: [Score]
nextToken: String
}
type Section {
id: ID!
title: String
subSection: String
questions: [Question]
}
type SectionConnection {
items: [Section]
nextToken: String
}
input TableQuestionFilterInput {
id: TableIDFilterInput
text: TableStringFilterInput
sectionId: TableIDFilterInput
}
input UpdateQuestionInput {
id: ID!
text: String
sectionId: ID
}
(I've redacted some of the schema as it was fairly large).
When I attempt to run the query:
mutation BatchCreateQuestions($sec: ID!) {
batchCreateQuestion(questions: [
{
text: "Tester 1"
sectionId: $sec
},
{
text: "Tester 2",
sectionId: $sec
}
]) {
id
text
sectionId
}
}
With the variables:
{ "sec": "abc123" }
I get the response:
{
"data": {
"batchCreateQuestion": [
null,
null
]
}
}
And when I check the DynamoDB table, it hasn't saved the values. I've granted full dynamodb permissions for this datasource, but still no joy.
Turns out I'd given batch write permissions to a similarly named role instead of the role affecting this data source. If you see a similar issue, check your IAM roles/permissions. Silly me.
What does your response template look like in the resolver? It should be $util.toJson($ctx.result.data.QuestionTable) based on the above table name being QuestionTable as that gets automatically translated into the response context.

Doctrine. Cache. Entity relations

I have two Entities Company and Storage with One-To-Many Bidirectional relationship. Entities and their relations are cached (doctrine second level cache). The issue is that, when i create a new Storage entity, Company storages collection doesn't have this new entity until I clear the cache manually.
AppBundle\Entity\Main\Company:
type: entity
table: main.company
cache:
usage: NONSTRICT_READ_WRITE
id:
id:
type: integer
nullable: false
id: true
generator:
strategy: IDENTITY
fields:
legalName:
type: string
nullable: false
length: 255
options:
fixed: false
column: legal_name
oneToMany:
storages:
targetEntity: AppBundle\Entity\Main\Storage
mappedBy: company
cascade: ["all"]
orphanRemoval: true
cache:
usage: NONSTRICT_READ_WRITE
AppBundle\Entity\Main\Storage:
type: entity
table: main.storage
cache:
usage: NONSTRICT_READ_WRITE
id:
id:
type: integer
nullable: false
options:
unsigned: false
id: true
generator:
strategy: IDENTITY
fields:
storageName:
type: string
nullable: true
length: 255
options:
fixed: false
column: storage_name
manyToOne:
company:
targetEntity: AppBundle\Entity\Main\Company
cascade: ["all"]
fetch: LAZY
mappedBy: null
inversedBy: storages
joinColumns:
company_id:
referencedColumnName: id
orphanRemoval: false
cache:
usage: NONSTRICT_READ_WRITE
This is action where Storage is created. There is nothing unusual.
public function addAction(Request $request)
{
$form = $this->createForm(StorageAddType::class, null);
$form->handleRequest($request);
if (!$form->isSubmitted()) {
throw new \RuntimeException('Некорректный запрос');
}
if (!$form->isValid()) {
throw new \Symfony\Component\Validator\Exception\ValidatorException((string)$form->getErrors(true));
}
$doctrine = $this->getDoctrine();
/**
* #var Storage $storage
*/
$storage = $form->getData();
$manager = $doctrine->getManager();
$manager->persist($storage);
$manager->flush();
return $this->createAjaxDataResponse($this->createSuccessMessage('Storage successfully added'));
}
Such behavior is watched only when i try to create new Entity (Storage). Then on update/delete actions - Storages collection of Company are updated.
You are clearly wrong with persisting data. You try to persist unserialized object from form into uknown repository via manager.
Try this:
public function addAction(Request $request)
{
$form = $this->createForm(StorageAddType::class, null);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
if($form->isSubmitted() && $form->isValid())
{
$storage = new Storage();
$storage->setVal1($form->get('Val1'));
$storage->setVal2($form->get('Val2'));
$em->persist($storage);
$em->flush();
return $this->createAjaxDataResponse($this->createSuccessMessage('Storage successfully added'));
}
return $this->render('YOUR_TWIG_LAYOUT', [
'form' => $form->createView()
]);
}
You can also try to persist whole object, if form is seriaized properly by serializing data into entity. Write method like setValsFromForm($data) and serialize vars from $data form.
Then change these lines:
$storage->setVal1($form->get('Val1'));
$storage->setVal2($form->get('Val2'));
into
$storage->setValsFromForm($form->getData());
Also:
Exceptions and form validations should be handled by Form Validator in form class, not in controller. Exception is when you create form via formbuilderinterface in the controller, but you add logic there, not outside $form class.

How to change a schema key?

I have a schema defined below and how can I change the predefined schema key (summary: key) via meteor template?
Schemas.Books = new SimpleSchema(
{
summary: {
type: String
}
}
);
For instance, I want to change this key through a session variable that was defined by router or through a user input.
Not Sure, Try this
If your schema is like this
Books = new SimpleSchema(
{
summary: {
type: String
}
}
);
then in tempalte helpers,
Books._schema.summary.type = function() {
return Session.get("typeValue");
};
In my project I have schema like this
RegisterSchema = new SimpleSchema({
name: {
type: String
},
email: {
type: String,
regEx: SimpleSchema.RegEx.Email
},
password: {
type: String,
label: "Password",
min: 8
},
confirmPassword: {
type: String,
label: "Confirm Password",
min: 8,
custom: function () {
if (this.value !== this.field('password').value) {
return "passwordMismatch";
}
}
}
});
and I'm dynamically setting optional value for email like
RegisterSchema._schema.email.optional = function() { return true };
this worked for me.
All d best
This is not the thing that I'm trying to do but I have learned a new trick : )
I want to change the schema key that I described above like this.
Books = new SimpleSchema(
{
bookName: {
type: String
}
}
);
Changing summary: with bookName:
Actually I want to define schema keys dynamically with respect to user information (userId, userName etc.).

Resources