Extbase looking for wrong table - typo3

I'm using TYPO3 7.4.0 and I'm learning to build extensions in extbase & fluid.
I have a vendor prefix in my table names. I create three tables for my extensions. When I go in the backend and add entities in the list view on the resource folder I created, it works without any problems. When I go to the Frontend to view the index action of my entity it looks for a table without the vendor prefix in it's name. Does anyone know what that means? I create the tables in the "ext_tables.sql". I have no table mapping defined. I don't know where to change which tables extbase is looking for.

By default Extbase looks for table using schema tx_extkey_domain_model_modelname, so for Animal model in zoo ext it will be tx_zoo_domain_model_animal. (extkey without underscore if any!)
If you used other schema (like vendor name within table name) you need to use mapping. I.e. create file ext_typoscript_setup.txt in main folder of your ext and use this:
config.tx_extbase{
persistence{
classes{
Vendor\Zoo\Domain\Model\Animal {
mapping {
tableName = tx_your_own_name
}
}
}
}
}
BTW: it's best idea to keep the original naming schema. Other thing is that creating extensions manually can be tricky - at least for beginners, install Extension Builder ext to fast kickstart new extensions just with click-click way.

Related

TYPO3 Extension Builder Integrate of existing table

I tried to integrate an existing table to my extension. The problem is that the content of the table isn't taken over.
I created a new model with the name of the existing table and named the properties according to the existing column names. I also implemented the corresponding getters and setters of the properties.
Extension
The name of the existing table is tx_institutsseminarverwaltung_domain_model_event.
How are you trying to "consume" or access the data from the other table in your extension?
Do you have a repository for the existing table (maybe there is already an existing repository, that you can reuse)?
See german typo3 board mapping existing tables and SO thread TYPO3 / How to make repository from existing table fe_users?
This question is most likely a duplicate of this question
The solution for this issues is:
First get the Typo3 query settings
$querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
Set RespectStoragePage to false
$querySettings->setRespectStoragePage(FALSE);
Fetch your repository
$theRepository = $this->objectManager->get('TYPO3\\institutsseminarverwaltung\\Domain\\Repository\\EventRepository');
And set the query settings to your repository.
$theRepository->setDefaultQuerySettings($querySettings);

jhipster - JPA entity with self reference

I am trying out jhipster and I wonder how to define a self reference within an entity.
Something like: a "topic" has a field refering itself as parent or child. Going through the generator I did not see a possibility to do so.
That`s why I generated a topic entity and added a field myself in the entity, howevever, it seems like changes in the entity are not picked up by liquibase.
Readint the docs it seems like the topic.json file from jhipster is parsed for this, but, that does not support the self reference. So I am kind of stuck here.
Any ideas how to achieve what I want?
Thanks,
Sven
liquibase creates the database tables using changelogs.
Look into the resources/config/liquibase/changelog folder
there should be a file named like "201531081212_added_entity_Topic.xml"
when you're adding properties, you have to change the table description of this changelog.
normally, it would be better to create a new, additional changelog when adding/removing columns or tables. This should contain somthing like this:
<addColumn tableName="TOPIC">
<column name="topic_id" type="bigint"/>
</addColumn>
or parent_id or how you named the field in the entity class.
asfair there are also some maven goals as part of the maven liquibase plugin to generate a new changelog.
Changing/Migrating entities is not yet supportet well by jhipster...

Extbase: get/save specific language of object

In a CommandController, I need to sync objects with an external source. The source is multi-language and shall be mapped to localized records in Typo3.
I just seem too blind to find options to ...
a) get records in a specific language
b) add/update records in a specific language
... (from a CommandController context).
I was expecting this to be a function of the model (AbstractEntity) or maybe the repository, but could not find any public lang/sys_lang/localize-functions there.
(Typo3 version 6.2)
You can write a method in your repository class to get all records with the sys_language_uid you need and use that method to get all the records.
If you model does not have the sys_language_uid, add it so you can use it in your controller.
(if your model has sys_laguage_uid, you can use $yourrepo->findBySysLanguageUid(1) )
Probably you need to change the defaultQuerySettings so you can retrieve the any language, regarding the site language (if you are using a FE ext)
adding the records with a specific language is $yourobject->setSysLangUid(1); (or whatever lang id)

TYPO3 Extension Error: Cannot create empty instance of the class

My FE plugin created using extension builder shows me the following error :
Cannot create empty instance of the class "TYPO3\CMS\Extbase\Persistence\ObjectStorage" because it does not implement the TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface.
What does it mean and how do I resolve it?
TYPO3 version 6.1.0
My Domain Object named Subject has relations Category_Id m:n relation and Location_Id 1:n relation . I did not map these two to any table during the creation of the extension.
How do I mention this in the extension that these relations are related to certain tables (Category_table and Location_table)and are to be looked in their respective domain model objects to retrieve data ?
The problem is a little confusing, I hope I made myself clear
Thank You
You need to set up the relation within the TCA.
Make sure to clear the cache and to remove the typo3temp/Cache/.
Then you will need to annotate your model properly such that extbase can resolve the reference.
Remember: TCA for core and annotation for extbase

Plural table names with Entity Frameworks Model First

I'm giving EF Model first a go. I'm using EF 4.1
Pretty much followed this article
I've set PluraliseNewObjects to False on the Model and also in Options->Database Tools ->O/R Designer set Pluralization of names to false.
Neither have any effect - when I generate a new schema from the model the table names are always pluralised - is it possible to disable this?
OK - I've found one way to achieve what I want - but it's a pretty daft route.
Generated db with the plural names (interesting that it only pluralised the tables mapping to types - not the auto-generated linking tables for many to many joins).
Manually renamed the tables in the database
Deleted Model from the project and recreated based on existing database schema (the one I've just renamed).
Model is now correctly mapped to singularly names tables.
I'll wait and see if anyone comes up with a more sensible way of achieving this....
The names of the tables in the generated DDL seem to match the "Entity Set Name" values (different than the "Entity Name"). If you singularize the Entity Set Names, the table names in the DDL are singularized as well.
This will have the possibly undesired effect of singularizing the EntitySet property names in your code, though. Instead of:
myDatabase
.Products
.Where...
.Select...
your code will look like:
myDatabase
.Product
.Where...
.Select...
may or may not be an issue