Single Table Inheritance and Yaml configuration - doctrine-orm

I want to use in my project Single Table Inheritance for symfony2/doctrine, but I can't find any working examples with yaml configuration for it. In official documentation there is only annotation configuration presented. I found xml examples, but I want to use yaml configuration. Can somebody help and share with some working code?

Okay built-in converter saves life.
In order to save time this an example of inheritance converted into yaml :
#file: Resources/config/doctrine/Person.orm.yml
Person:
type: entity
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
inheritanceType: SINGLE_TABLE
discriminatorColumn:
name: discr
type: string
length: 255
discriminatorMap:
person: Person
employee: Employee
lifecycleCallbacks: { }
#file: Resources/config/doctrine/Employee.orm.yml
Employee:
type: entity
table: null
lifecycleCallbacks: { }

Here is an example of YAML markup:
Entities config files should be put into src/Acme/StoreBundle/Resources/config/doctrine/<EntityName>.orm.yml according to reference.
Also built-in converter can be used: how to model inheritance in doctrine2 with yaml?

Related

Plop.js Template files adding a root directory in the destination folder

I'm running into an issue unsure if it's me.
I'm using Plop.js within a project to quickly code generate boilerplate (bp) for new packages.
I've got 4 different template folders that plop maps from when a user enters the generate command.
User is prompted with a list of package types to create:
choices: ['react', 'node', 'browser', 'isomorphic'],
Based on the users response to the prompts, plop chooses the folder to pull the template files from.
Template folder structure looks like this:
plop-template/
- react/
- node/
- browser/
- isomorphic/
The templateFiles: property is correctly identifying and creating the bp based on the user response.
templateFiles: 'plop_templates/{{project-type}}/**/*/',
the issue i'm running into is the project-type is being added to the file destination path
So what i would like to occur is the
/project-name/ ... boiler plate created
But what is happening is:
/project-name/project-type/ ... boiler plate created
So, is it possible to remove the /project-type/ from the destination path?
Plopfile.js (v. "plop": "3.1.1"):
const findEtensionFile = require("../lib/file-extention-locator");
module.exports = function (plop) {
plop.getDestBasePath;
plop.setGenerator("component", {
prompts: [
{
type: "input",
name: "project-name",
message: "What's the name your project? ",
},
{
type: "list",
name: "project-type",
message: "Project Type:",
choices: ["react", "node", "browser", "isomorphic"],
},
],
actions: function (data) {
var actions = [];
actions.push({
type: "addMany",
globOptions: { dot: true },
destination: "../../../{{project-name}}",
base: "/",
templateFiles: "plop_templates/{{project-type}}/**/*/",
});
return actions;
},
});
};
What I've tried:
filter: property ... This can be used to modify the file contents, seems like that only affects the
base: property (string).. documentation seems to indicate this is the route where I can filter out but can't find a value that doesn't break BP creation.
Any help would be greatly appreciated.
Discovered the error was mine.
Seems like the base: value must match the entire value for templateFiles.
In this case:
base: 'plop_templates/{{project-type}}',
templateFiles: "plop_templates/{{project-type}}/**/*/",
Even though the /plop_templates/ folder wasn't being created in the path.

How to match AmChart GeoJson data using string

I'm trying to plot some counts per State county using AmCharts and their GeoJson file. For example, loading FL counties and adding the counts. However, it seems I need to know the ID of the county, and not just the name. Is there a way to match the GeoJson using the county name?
I tried the simple idea of accessing the properties "name" in the GeoJson data and adding the count in polygonSeries.data but that doesn't work. It only works when providing the id.
When adding data, AmCharts allows something like this
polygonSeries.data =[
{ id: "12133", value: 60.524 }, // Washington
{ id: "12131", value: 300 }, // Walton
{ id: "12129", value: 500 }, // Wakulla
];
The above works. The below doesn't
polygonSeries.data = [
{ name: "Washington", value: 60.524 }, // Washington
{ name: "Walton", value: 300 }, // Walton
{ name: "Wakulla", value: 500 }, // Wakulla
];
The GeoJson data contains the relevant information like this
properties:{name:"Washington",id:"12133",STATE:"FL",TYPE:"County",CNTRY:"USA"},id:"12133"}
It apparently is matching the properties.id to find the object and that's why it works with the ids. However, that means I would need to know the ID for every county to begin with.
So is there a way to match using the county name instead?
I would expect AmCharts to match the relevant properties and not just the ID since those are relatively unknown to people.
After speaking to amChart support, it's not possible to do this.

Loopback 4 - Eager Load Detail Table

I'm new to Loopback 4 and am having an issue mapping our current database structure to the ORM. We currently use detail tables a lot to store secondary object data, such as addresses. For example we might have two tables related as so:
"Offices" table
id: string;
officeName: string; "Addresses" table
addressId: string; ============> id: string;
line1: string;
line2: string;
city: string;
state: string;
zip: number;
Then we use a DTO to map the data as follows:
"Office" DTO
id: string;
officeName: string;
addressLine1: string;
addressLine2: string;
addressCity: string;
addressState: string;
addressZip: number;
However i'm having trouble figuring out how to eager load the address detail table so when I create the DTO using the model it will map correctly. I can see how to do this manually, but I'm looking for a solution that eager loads the child "address" record with the parent "office" record.
For reference I've set up my models and repositories as documented here:
https://loopback.io/doc/en/lb4/BelongsTo-relation.html
The office belongs to the address, since the address primary key is stored in the office record.
Update: Turns out this is not possible/hasn't been implemented yet. Our next solution will unfortunately not include Loopback due to this.
Source: https://github.com/strongloop/loopback-next/issues/1352

RAML 1.0, Map types complex regular expression

In my api, I have a type who contains a map of uuid->Drive. I have used a Map type[1] to define that :
type: object
properties:
drives:
required: false
type: object
properties:
[(a-zA-Z0-9-)*] :
type: Drive
That work but I would like to be more precise on the pattern. However I can't manage to have it working.
["(a-zA-Z0-9){8}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){12}"]: Don't seems to be used as regular expression.
[(a-zA-Z0-9){8}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){4}-(a-zA-Z0-9){12}]: Say Missed comma between flow collection entries
How can I use a complex expession in a Map type with RAML 1.0 ?
(I'm using API Workbench)
[1] http://docs.raml.org/specs/1.0/#raml-10-spec-map-types
Using patternProperties instead of the alternative syntax I don't have any errors in my RAML. However it seems that, API Workbench validates nothing.
You need to use a RegEx string that starts with /^ and ends with $/
#%RAML 1.0
title: My API With Types
types:
Person:
properties:
name:
required: true
type: string
age:
required: false
type: number
/^note\d+$/: # restrict any properties whose keys start with "note"
# followed by a string of one or more digits
type: string
https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#additional-properties

Doctrine2 lifecycleCallbacks prePersist not firing w/YAML config

All my Doctrine2 setups are done within YAML files. I have an entity class named LoanAppMenuProgress where I'm trying to execute a prePersist function. This LoanAppMenuProgress entity has a oneToOne relationship with another class named LoanApp. There is a foreign key association on the LoanAppMenuProgress table associated with the LoanApp table in the DB.
I have this config for my LoanAppMenuProgress class in LoanApp.LoanAppMenuProgress.orm.yml:
LoanEv\LoanAppBundle\Entity\LoanApp\LoanAppMenuProgress:
type: entity
repositoryClass: LoanEv\LoanAppBundle\Repository\LoanApp\LoanAppMenuProgress
table: loan_app_menu_progress
id:
id:
type: integer
generator: { strategy: auto }
### This is the OWNING side of the relationship
oneToOne:
loan_app:
targetEntity: LoanApp
inversedBy: loanapp_menu
joinColumn:
name: loan_id
referencedColumnName: id
fields:
loan_id:
type: integer
menu_id2:
type: integer
menu_id3:
type: integer
menu_id4:
type: integer
lifecycleCallbacks:
prePersist: [ updateMainMenuStatus ]
This is my LoanApp.LoanApp.orm.yml file:
LoanEv\LoanAppBundle\Entity\LoanApp\LoanApp:
type: entity
repositoryClass: LoanEv\LoanAppBundle\Repository\LoanApp\LoanAppRepository
table: loan_app
id:
id:
type: integer
generator: { strategy: auto }
## This is the INVERSE side of the relationship.
oneToOne:
loanapp_menu:
targetEntity: LoanAppMenuProgress
mappedBy: loan_app
fields:
bank_id:
type: integer
# etc.
In my LoanAppMenuProgress Entity class, I have the following code:
namespace LoanEv\LoanAppBundle\Entity\LoanApp;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Util\Debug;
/**
* LoanEv\LoanAppBundle\Entity\LoanApp\LoanAppMenuProgress
*/
class LoanAppMenuProgress
{
private $id;
private $loan_id;
/**
* #var LoanEv\LoanAppBundle\Entity\LoanApp\LoanApp
*/
private $loan_app;
private $menu_id2 = 0;
private $menu_id3 = 0;
private $menu_id4 = 0;
// ...
public function updateMainMenuStatus()
{
echo("Inside prePersist's updateMainMenuStatus function. ");
}
}
The following code is called from within my LoanAppController class:
// ...
//Save the menuStatus changes.
echo("About to persist. ");
$em->persist($menuStatus[0]);
echo("Done persisting.");
$em->flush();
// ...
When I execute the code in the LoanAppController the following gets written to my screen:
"About to persist. Done persisting."
I'm missing that bit in the middle where the output should read:
"About to persist. Inside prePersist's updateMainMenuStatus function. Done persisting."
The changes ARE getting written to the database, and all the functionality of the system is working as expected with the exception of the prePersist(). I've struggled with the yml setups for quite a while so my initial assumption is that my YAML setup is incorrect.
The documentation (as far as I could understand it) mentions that I should add the lifecycleCallbacks: and prePersist: items to the yml file, and then make sure I have a public function in the persisting Entity. Obviously, I'm missing something.
Does anyone have any ideas?
Thanks.
prePersist only gets called when you are performing an INSERT type statement. This event will never fire on an UPDATE action.
To perform some action when an entity is being UPDATEd, use preUpdate. Note, that preUpdate has far more restrictions on what can be performed with the entity in question.
Derrick