Symfony's Gedmo Tree throws sorting error - symfony

Following Gedmo Tree manual I'd like to get tree of categories like the documentation shows:
$repository = $entityManager->getRepository(Category::class); $tree = $repository->childrenHierarchy();
however it throws an exception:
Invalid sort options specified: field - root, direction - asc

I faced the same issue and had to rollback the gedmo/doctrine-extensions version 3.7.

Related

Navigations can only target entity types with keys

I am working on a project with a 'database first' approach rest API backend. I am using ASP .Net Core 3.1 and Entity Framework 3.1.1.
I ran a script to scaffold the database into the models and db context class. However, some of the model building functions have tables/models without keys x.hasnokey(). I thought this would be fine but I get an error trying to hit the endpoint that states
ERROR : InvalidOperationException:
The navigation '' cannot be added because it targets the keyless entity type 'AAA'
Navigations can only target entity types with keys
This happens in a few different locations and this originally ran okay in the past. This is running on SQL Server 2012 (version 11). I am not sure how I can solve this issue, I have limited entity/sql experience and I just don't know where to begin. Here is the offending lines (inside DB Context):
modelBuilder.Entity<AAA>(entity =>
{
entity.HasNoKey();
entity.ToTable("BBB_AAA");
entity.HasOne(d => d.BBB)
.WithMany(p => p.AAA)
.HasForeignKey(d => d.CCC)
.OnDelete(DeleteBehavior.ClientSetNull)
...
}
The script I used to scaffold the models and db context was (generic version):
PM> Scaffold-DbContext "Server=.\SQLExpress;Database=SchoolDB;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
I believe this might be that the database that was originally created about 10-15 years ago, cannot be made into an ORM so easily as I would have hoped. It could also a versioning issue, the scaffolding script I ran is incorrect, or if I just am out of my depth but I would appreciate being pointed in the right direction. Thank you!
This error usually comes because of Primary Key issue.
In my Case I was running this query and result was same problem you mentioned
var exists = await _dbDontext.Students.FindAsync(Id);
My Student table has relations with other tables and one of other tables was missing Primary Key.
So two Possible Solutions .
Solution 1 :
Make Primary Key column in your table that is mentioned in your error.
Solution 2 :
If things are complicated , just delete the table and Re Create It. It would work fine
I think you have two options,
1- Go and add key to the table.
2- check the following link
https://learn.microsoft.com/en-us/ef/core/modeling/keyless-entity-types
Thanks

Drupal 8: Mismatched entity and/or field definitions

While trying to understand why my view is not displaying, I noticed the following error in the log:
I do not think it is possible to delete the URL alias from Taxonomy terms. At least I cannot find how to do this.
I have, however gone through ALL of my taxonomy terms and removed the value for this field.
I have also done the following with Pathauto:
Also, I have checked the report located at admin/reports/fields and can confirm that there are no entities that use a field called URL alias.
I have gone through each content item and ensured that they have the following setting (anyone know how to do this in bulk?). But still the error remains.
Anyone know then how I can fix this strange error?
Im not entirely sure what this command does, but it fixed the error:
drush updb --entity-updates
Since https://www.drupal.org/node/2554097, the magic in Drupal core that took care of updating entity definitions is gone. drush updb --entiy-updates is an alternative to this but it is not a silver bullet. Instead, it is safer to write database updates.
Taking the screenshot at the top as an example, here is a database update that would delete those two field definitions:
/**
* Fix taxonomy and node field definitions.
*
*/
function mymodule_update_8101() {
$manager = \Drupal::entityDefinitionUpdateManager();
if ($field = $manager->getFieldStorageDefinition('alias', 'node')) {
$manager->uninstallFieldStorageDefinition($field);
}
if ($field = $manager->getFieldStorageDefinition('alias', 'term')) {
$manager->uninstallFieldStorageDefinition($field);
}
}
Have a look at the rest of the available methods at https://www.drupal.org/node/2554097 in order to write database updates for each scenario.
use the entity_update module or the devel_entity_updates module

How do I use SQL LEFT() in Symfony2 query builder?

Here's the line that's making my query fail.
$query = $query->where('a.field LIKE :keyword OR LEFT(a.otherfield, 3) = LEFT(:keyword, 3)');
I get this error:
[Syntax Error] line 0, col 104: Error: Expected known function, got 'LEFT'
This SQL code works:
SELECT * FROM `table`
WHERE field LIKE 'searchterm'
OR LEFT(`otherfield`, 3) = LEFT('searchterm', 3)
Why does LEFT() return an error? Is there a different way to do it with query builder?
Try to look at this question. Otherwise, try the old school way! native-sql-with-doctrine.
#Houssem Zitoun's answer was good, and I'm marking it as the answer because it's relevant to my question. It's not the answer I used however
I already had the query written in sql that I wanted to use, so i decided to use a custom query with doctrine. It explains here how to do it. Symfony2 & Doctrine: Create custom SQL-Query

SONATA_TYPE_MODEL_AUTOCOMPLETE does not work

with sonata Admin bundle dev-master, I've relationship like Many Vote can be linked to only One PollingStation as the number of the PollingStation entities are so plenty (over 40000) I've to use SONATA_TYPE_MODEL_AUTOCOMPLETE (propose any best way if you think it exists) but after setting up the configureFormFields like in the official documentation, I get the following error:
Notice: Undefined index: read_only
$builder->setAttribute('minimum_input_length', $options['minimum_input_length']);
$builder->setAttribute('items_per_page', $options['items_per_page']);
$builder->setAttribute('req_param_name_page_number', $options['req_param_name_page_number']);
$builder->setAttribute('disabled', $options['disabled'] || $options['read_only']);
$builder->setAttribute('to_string_callback', $options['to_string_callback']);
The issue has been fixed by the sonata project contributors long time ago so just do:
composer udpate

Alfresco: Unable to CMIS query by path

I am trying to find out the contents of a folder in Alfresco, using the following CMIS query:
SELECT *
FROM cmis:document
WHERE CONTAINS('PATH:"/app:company_home/st:sites/cm:GM/cm:emir/cm:FAQ//*"')
In Node Browser, if I navigate to that folder I see the following value for Primary Path
(I have added line breaks to make it easier to read):
/{http://www.alfresco.org/model/application/1.0}company_home
/{http://www.alfresco.org/model/site/1.0}sites
/{http://www.alfresco.org/model/content/1.0}GM
/{http://www.alfresco.org/model/content/1.0}EMIR
/{http://www.alfresco.org/model/content/1.0}FAQ
But Alfresco is failing with the following message:
Caused by: org.alfresco.scripts.ScriptException: 05120032 Failed to
execute script
'classpath*:alfresco/templates/webscripts/org/alfresco/cmis/queries.post.cmisquery.js':
05120 031 Unknown column/property PATH
I am testing against Alfresco Community 3.3.
You can use the following query for simple search
SELECT * FROM cmis:document WHERE IN_FOLDER('id_of_folder')
or the following query for recursive search
SELECT * FROM cmis:document WHERE IN_TREE('id_of_folder').
if you want search by path, you can use:
SELECT * FROM cmis:folder
WHERE CONTAINS('PATH:\"/app:company_home/st:sites/cm:my_site/cm:documentLibrary//*\"')
For more details view also the official specification
http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html
Do yourself a favor and upgrade.
Your query works for me in the share node browser (does not throw exceptions) as either cmis-strict or cmis-alfresco .
SELECT *
FROM cmis:document
WHERE CONTAINS('PATH:"/app:company_home/st:sites//*"')
Gives me a whole lot of results.

Resources