How to generate entities and update database schema in Silex - doctrine-orm

I use doctrine ORM
I create entity without console. It looks like
Trololo\Event:
type: entity
table: events
readOnly: false
id:
id:
type: guid
generator:
strategy: UUID
fields:
dateCreated:
type: datetime
nullable: false
name:
type: string
length: 75
startDate:
type: datetime
nullable: false
How can I tell doctrine, for this filed? I need create database, now I need
create table.

By default, Silex support only the DBALpackage of Doctrine for database. If you want to use the ORMpackage and have it integrated in your application, you would have to use a ServiceProvider
List of a few services providers for Silex
To use the command line for building your database/schema, you will have to use doctrine command lines from the library itself (it's not wrapped in console as it is in Symfony)
Here is the list of Doctrine's commands

Related

How to add a unique constraints through Loopback 4 Model?

I have a Department model in my project. The properties are id, name. name of course should be unique. However I can't seem to look where the setting is so I can put something like
#model()
export class Department extends Entity {
#property({
type: 'number',
id: true,
generated: true,
})
id?: number;
#property({
type: 'string',
required: true,
unique: true // ---> This is what I want. But how?
})
name: string;
constructor(data?: Partial<Department>) {
super(data);
}
}
I tried digging to Model documentation, it seems that there is something I can do with the #model decorator. However I found no documentation about it.
Also, I want to do this in PostgreSQL as a datasource. Any clue? Any advice would be appreciated.
#property({
type: 'string',
required: true,
index: {
unique: true,
}
})
name: string;
Using index object.
Migrate Database - Modify or alter table
run command : npm run build
migrate database : npm run migrate

Loopback 4: non-primitive properties instead of relations

Using Loopback 4, I want to use the type-safety of Typescript in my application code while getting the schema validation from the repository decorators, but store a property as serialized json (in this case, Postgres bson) instead of as a separate entity with a FK relation.
Consider a address book Contact model that could have a list of phone numbers:
#model()
export class PhoneNumber {
#property({ required: true })
number: string;
#property()
type: string;
}
#model()
export class Contact extends Entity {
#property({ id: true, required: true })
id: string;
#property({ required: true })
email: string;
#property({ required: true })
name: string;
#property.array(PhoneNumber)
phoneNumbers: PhoneNumber[];
constructor(data?: Partial<Contact>) {
super(data);
}
}
In the above example, I get full schema validation, but if I try to save an instance of Contact using a generated Repository that extends DefaultCrudRespository, it just drops whatever was provided in the phoneNumbers field and saves an empty column in the db.
If I change the property annotation to:
#property.array(Object)
phoneNumbers: PhoneNumber[];
It will save the field properly, serialized as json, but it won't attempt to validate the field, and also won't specify the type as an array PhoneNumber in the generated openapi.json spec
It seems that Loopback 3 had support for embedded models: https://loopback.io/doc/en/lb3/Embedded-models-and-relations.html
No mention of it in the Loopback 4 docs, though.
Try use the strict mode filter in the model PhoneNumber
#model({settings: {strict: "filter"}})
This make any unknow field be ignored when add in the database

DynamoDB AppSync field resolvers timing out

So I have the schema below. If I try to query data off this schema AppSync will time out saying 'NetworkError when attempting to fetch resource.'
type Model {
PartitionKey: ID!
SortKey: ID!
Name: String
Version: Int
FBX: String
# ms since epoch
CreatedAt: AWSTimestamp
Description: String
Tags: [Tag]
}
type ImageSet {
PartitionKey: ID!
SortKey: ID!
Name: String
CreatedAt: AWSTimestamp
Description: String
Tags: [String]
}
Now, if I change 'Name' in the model to 'ModelName' then queries on that will work. If I change 'Name' in ImageSet to 'SetName' then queries on that will work.
What is going on with this? What is wrong with the 'Name' field name? 'Description' and 'CreatedAt' do not have this issue.
Edit
Actually I am encountering this happening with other fields in the
schema as well. Please help.
I do have resolvers attached to specific fields. Removing them does
solve the problem. Am I not supposed to attach revolvers to specific
fields or is something else wrong?
-
Edit 2
This really does seem to only occur if the name of a field is shared
between different schema objects, is that not allowed!?

JSON API group and subgroup EmberJS

So I want to build the following select dropdown in ember, using ember data and the API is going to be using the JSON API spec. Here is a screenshot example
So would I in the services model, state the following
app/model/service.js
category: DS.belongsTo('category'),
subCategory: DS.belongsTo('sub-category')
app/model/category.js
service: DS.hasMany('service'),
subCategory: DS.belongsTo('category')
app/model/category.js
service: DS.hasMany('service'),
category: DS.belongsTo('sub-category')
I feel like I am missing something? Thoughts
I think want you're missing is this:
export DS.Model.extend({
parent: DS.belongsTo('category', { inverse: 'children'}),
children: DS.hasMany('category', { inverse: 'parent' }),
});
this will allow you to have a parent/child relationship with one model. If you want a different model for the sub-category I don't really understand whats your problem is.

Ember Data Relationships against non standard API

I want to use Ember Data but the API I am coding against does not respect all the conventions.
My problem is that the API does not return sideloaded relationships but relationships should be loaded using a REST structure: /model/id/relationship.
I have the following model:
Library = DS.Model.extend
name: DS.attr 'string'
groups: DS.hasMany 'group', {async: true}
groupsCount: DS.attr 'number'
The payload looks like:
{
library: {
groups_count: 44,
name: "demo",
id: "545262a063726d2514390100"
}
}
When I attempt to load groups using library.get('groups') nothing happens. It should make a call to libraries/545262a063726d2514390100/groups
Can I change my RESTAdapter to make this work?
After some research I found a way that works for me:
LibrarySerializer = DS.RESTSerializer.extend
normalize: (type, hash, prop)->
hash.links =
groups: "groups"
#_super(type, hash, prop)
This essentially adds a links object to the response, making the rest adapter follow that path to retrieve the relationship.