[TYPO3-mvc] Add object fails

Gianluca Strafella gianluca.strafella at webformat.com
Mon Sep 29 14:21:05 CEST 2014


Hi Valeria,
I don't know if is not possibile use foreign keys with Extbase Model but 
it sounds strange.
You wrote:

"Calling to method add() of repository I always have an error: Cannot 
add or update a child row: a foreign key constraint fails. "

My question is this:

Did you try to debug your model instance, BEFORE to add it on repository 
? With this, you could see if property 'category' is null or it contains 
some value. In last one, you should see if a category with that 'id' 
already exists on database when you add your model in repository. If 
not, you should add category to Category Repository before to add your 
main model instance to its repository.

Another question is: in your model class, is there a property category 
with its PHP annotation ? In example:

class YourModel extends ... {

  /**
   * searchword
   *
   * @var yourCategoryModelClass
   */
   protected $category;

//  getter

//  setter	

}


Cheers,

Gianluca Strafella

Software Developer
gianluca.strafella at webformat.com

WEBFORMAT srl – www.webformat.com


Il 29/09/2014 11:17, Valeria Tabolsky ha scritto:
> Thank you Gianluca,
>
> no my model doesn't extend another, but the table schema had foreign key
> constraint. As I understand Typo3 models doesn't allow it. Once I
> removed foreign key everything works fine.
> Here is the configuration of property 'category', it still has
> 'foreign_table' but only on typoscript  level not in DB schema.
>
> If there is a possibility to use foreign keys, i'd like to.
>
>
>          'category' => array(
>              'exclude' => 1,
>              'label' =>
> 'LLL:EXT:links/Resources/Private/Language/locallang_db.xlf:tx_links_domain_model_link.category',
>
>              'config' => array(
>                  'type' => 'select',
>                  'foreign_table' => 'tx_links_domain_model_linkcategory',
>                  'foreign_table_where' => 'AND
> tx_links_domain_model_linkcategory.pid = ###CURRENT_PID###',
>
>                  'size' => 4,
>                  'eval' => 'int'
>              )
>          ),
>
> Cheers,
> Valeria


More information about the TYPO3-project-typo3v4mvc mailing list