Skip to content

Instantly share code, notes, and snippets.

@meshenka
Created February 6, 2019 14:03
Show Gist options
  • Save meshenka/47011570b3d5b1d01552620da3c1a852 to your computer and use it in GitHub Desktop.
Save meshenka/47011570b3d5b1d01552620da3c1a852 to your computer and use it in GitHub Desktop.
Field Mapping issue Sf 4.2
{
"name": "meshenka/test-sf4",
"type": "project",
"license": "proprietary",
"description": "A test project with Symfony4",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/dotenv": "*",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"doctrine/doctrine-migrations-bundle": "^2.0",
"sensio/framework-extra-bundle": "^5.1",
"symfony/console": "*",
"symfony/flex": "^1.1",
"symfony/form": "^4.0",
"symfony/framework-bundle": "*",
"symfony/orm-pack": "^1.0",
"symfony/security-csrf": "^4.0",
"symfony/twig-bundle": "^4.0",
"symfony/validator": "^4.0",
"symfony/yaml": "*"
},
"require-dev": {
"phpspec/phpspec": "^5.1",
"sensiolabs/security-checker": "^4.1",
"symfony/debug-bundle": "^4.0",
"symfony/debug-pack": "^1.0",
"symfony/maker-bundle": "^1.11",
"symfony/phpunit-bridge": "^4.0",
"symfony/profiler-pack": "^1.0",
"symfony/web-server-bundle": "^4.0",
"symfony/webpack-encore-pack": "^1.0"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true,
"bin-dir": "bin"
},
"autoload": {
"psr-4": {
"App\\": "src/"
},
"psr-0": {"": "src"}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-apcu": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd",
"security-checker security:check": "script"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"id": "01C16NRNSRB9Z0474E39P63C0R",
"allow-contrib": false
}
}
}
bin/console doctrine:mapping:info
Found 1 mapped entities:
[OK] App\Store\Entity\ProductEntity
bin/console doctrine:schema:create --dump-sql
The following SQL statements will be executed:
bin/console doctrine:schema:validate
Mapping
-------
[OK] The mapping files are correct.
Database
--------
[OK] The database schema is in sync with the mapping files.
bin/console --version
Symfony 4.2.2 (env: dev, debug: true)
#pleaz help ma!! >__<
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App\Store:
is_bundle: false
type: xml
dir: '%kernel.project_dir%/src/Resources/config/doctrine'
prefix: 'App\Store\Entity'
alias: Store
namespace App\Domain\Model;
abstract class Product implements ProductInterface {
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $name;
/**
* @var float
*/
protected $price;
/**
* @var string
*/
protected $description;
/**
* getName
*
* @return string
*/
public function getName() : string
{
return $this->name;
}
public function getId() : int
{
return $this->id;
}
// all accessors
}
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="App\Store\Entity\ProductEntity"
table="product"
schema="schema_name"
repository-class="App\Store\Repository\ProductRepository"
read-only="false">
<id name="id"
type="integer">
<generator strategy="AUTO" />
</id>
<indexes>
<index name="name_index"
columns="name"/>
</indexes>
<field name="name"
type="string"
length="50"
column="name"/>
<field name="price"
type="decimal"
precision="2"
scale="7">
<options>
<option name="comment">Price in Euro</option>
<option name="default">0.0</option>
</options>
</field>
<field name="description"
type="text"
length="50"
nullable="true"/>
<field name="slug"
type="string"
length="255"
nullable="false">
<options>
<option name="comment">slug is used to generate url to the product page</option>
</options>
</field>
</entity>
</doctrine-mapping>
namespace App\Store\Entity;
use App\Domain\Model\Product;
class ProductEntity extends Product
{
protected $slug;
/**
* Get the value of slug
*/
public function getSlug(): string
{
return $this->slug;
}
/**
* Set the value of slug
*
* @return self
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment