2017-11-20 1 views
0

商品のレートを複数通貨で管理し、通貨の歴史を維持したいと考えています。Symfony 3&Doctrine - OnetoManyとManyToManyの関係を持つ複雑なフォーム

だからonetomany関係: レートは、多くのCurrencyRateを持つことができます。

A many many関係: 多くのcurrencyRateには多くの通貨があります。

料金:

+-----------------+----------+------+-----+---------+----------------+ 
| Field   | Type  | Null | Key | Default | Extra   | 
+-----------------+----------+------+-----+---------+----------------+ 
| id    | int(11) | NO | PRI | NULL | auto_increment | 
| rate   | double | YES |  | NULL |    | 
| timeStamp  | datetime | NO |  | NULL |    | 
| currencyRate_id | int(11) | YES | MUL | NULL |    | 
+-----------------+----------+------+-----+---------+----------------+ 

通貨率

+-----------+----------+------+-----+---------+----------------+ 
| Field  | Type  | Null | Key | Default | Extra   | 
+-----------+----------+------+-----+---------+----------------+ 
| id  | int(11) | NO | PRI | NULL | auto_increment | 
| rate  | double | NO |  | NULL |    | 
| timeStamp | datetime | NO |  | NULL |    | 
+-----------+----------+------+-----+---------+----------------+ 

currencyrateshascurrencies(結合テーブルを多対多)

+-----------------+---------+------+-----+---------+-------+ 
| Field   | Type | Null | Key | Default | Extra | 
+-----------------+---------+------+-----+---------+-------+ 
| currency_id  | int(11) | NO | PRI | NULL |  | 
| currencyRate_id | int(11) | NO | PRI | NULL |  | 
+-----------------+---------+------+-----+---------+-------+ 

通貨

+-------------+--------------+------+-----+---------+----------------+ 
| Field  | Type   | Null | Key | Default | Extra   | 
+-------------+--------------+------+-----+---------+----------------+ 
| id   | int(11)  | NO | PRI | NULL | auto_increment | 
| name  | varchar(255) | NO | UNI | NULL |    | 
| abreviation | varchar(5) | NO | UNI | NULL |    | 
+-------------+--------------+------+-----+---------+----------------+ 

私はこのすべてからフォームを生成したいと思います。 htmlフォームは、CurrencyRateを示すテキストフィールドを持つ使用可能なすべての通貨を取得します。 例:

USD <input type="text"> 
EUR <input type="text"> 
CNY <input type="text"> 
... 

私は、多対多の形式についてのSymfonyのドキュメントを見ました。しかし、私のものは、onetomany関係とテキストフィールドを追加することによって、より複雑です。私は完全に失われています。

私を正しい方向に向けることができれば、ありがとう。

敬具、

ピエール

+0

Oula、私は私はすべてのアップを混合だと思います。私は私が推測する多くの関係を必要としません。すぐに自分を訂正します – 123pierre

答えて

0

は私が応答を見つけました:

まず、私は多対多の関係を必要としなかった私のスキーマを修正するために必要な:

料金:

+-----------+----------+------+-----+---------+----------------+ 
| Field  | Type  | Null | Key | Default | Extra   | 
+-----------+----------+------+-----+---------+----------------+ 
| id  | int(11) | NO | PRI | NULL | auto_increment | 
| rate  | double | YES |  | NULL |    | 
| timeStamp | datetime | NO |  | NULL |    | 
+-----------+----------+------+-----+---------+----------------+ 

通貨レート

+-------------+---------+------+-----+---------+----------------+ 
| Field  | Type | Null | Key | Default | Extra   | 
+-------------+---------+------+-----+---------+----------------+ 
| id   | int(11) | NO | PRI | NULL | auto_increment | 
| ratio  | double | NO |  | NULL |    | 
| currency_id | int(11) | YES | MUL | NULL |    | 
| Rate_id  | int(11) | YES | MUL | NULL |    | 
+-------------+---------+------+-----+---------+----------------+ 

通貨

+-------------+--------------+------+-----+---------+----------------+ 
| Field  | Type   | Null | Key | Default | Extra   | 
+-------------+--------------+------+-----+---------+----------------+ 
| id   | int(11)  | NO | PRI | NULL | auto_increment | 
| name  | varchar(255) | NO | UNI | NULL |    | 
| abreviation | varchar(5) | NO | UNI | NULL |    | 
+-------------+--------------+------+-----+---------+----------------+ 

そして、一つのフォームタイプ、最終的なフォームタイプに埋め込まれ

class CurrencyRateType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('currency',EntityType::class, array(
           'class'=>'AppBundle:Currencies', 
           'choice_label' => 'abreviation', 
           'disabled' => true, 
       )) 
       ->add('ratio', TextType::class); 
    } 

    public function configureOptions(OptionsResolver $resolver) 
    { 
     $resolver->setDefaults(array(
      'data_class' => CurrencyRates::class, 
     )); 
    } 
} 

class RateType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder ->add('rate') 
        ->add('CurrencyRate', CollectionType::class, array(
      'entry_type' => CurrencyRateType::class, 
      'entry_options' => array('label' => false)) 
      ) 
        ->add('save', SubmitType::class, array('label' => 'create')); 
    } 

    public function configureOptions(OptionsResolver $resolver) 
    { 
     $resolver->setDefaults(array(
      'data_class' => Rates::class, 
     )); 
    } 
} 
関連する問題