Skip to content

Commit

Permalink
[JPA] Correction bug lorsque plusieurs clés primaire
Browse files Browse the repository at this point in the history
  • Loading branch information
gideruette committed Oct 2, 2023
1 parent cda1bde commit a7ec5b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
26 changes: 13 additions & 13 deletions TopModel.Generator.Jpa/JpaEnumGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,25 @@ public JpaEnumGenerator(ILogger<JpaEnumGenerator> logger, ModelConfig modelConfi
}

public override string Name => "JpaEnumGen";
public override IEnumerable<string> GeneratedFiles => Files.Values.SelectMany(f => f.Classes.Where(FilterClass))
.SelectMany(c => Config.Tags.Intersect(c.Tags).SelectMany(tag => GetEnumProperties(c).Select(p => GetFileName(p, c, tag)))).Distinct();

protected bool FilterClass(Class classe)
{
return !classe.Abstract && Config.CanClassUseEnums(classe, Classes.ToList());
}
public override IEnumerable<string> GeneratedFiles => Files.Values.SelectMany(f => f.Classes.Where(FilterClass))
.SelectMany(c => Config.Tags.Intersect(c.Tags).SelectMany(tag => GetEnumProperties(c).Select(p => GetFileName(p, c, tag)))).Distinct();

protected string GetFileName(IFieldProperty property, Class classe, string tag)
{
return Config.GetEnumFileName(property, classe, tag);
}

private IEnumerable<IFieldProperty> GetEnumProperties(Class classe)
protected void HandleClass(Class classe, string tag)
{
List<IFieldProperty> result = new();
if (classe.EnumKey != null && Config.CanClassUseEnums(classe, prop: classe.EnumKey))
foreach (var p in GetEnumProperties(classe))
{
result.Add(classe.EnumKey);
WriteEnum(p, classe, tag);
}

var uks = classe.UniqueKeys.Where(uk => uk.Count == 1 && Config.CanClassUseEnums(classe, Classes, uk.Single())).Select(uk => uk.Single());
result.AddRange(uks);
return result;
}

protected override void HandleFiles(IEnumerable<ModelFile> files)
Expand All @@ -59,12 +54,17 @@ protected override void HandleFiles(IEnumerable<ModelFile> files)
}
}

protected void HandleClass(Class classe, string tag)
private IEnumerable<IFieldProperty> GetEnumProperties(Class classe)
{
foreach (var p in GetEnumProperties(classe))
List<IFieldProperty> result = new();
if (classe.EnumKey != null && Config.CanClassUseEnums(classe, prop: classe.EnumKey))
{
WriteEnum(p, classe, tag);
result.Add(classe.EnumKey);
}

var uks = classe.UniqueKeys.Where(uk => uk.Count == 1 && Config.CanClassUseEnums(classe, Classes, uk.Single())).Select(uk => uk.Single());
result.AddRange(uks);
return result;
}

private void WriteEnum(IFieldProperty property, Class classe, string tag)
Expand Down
3 changes: 1 addition & 2 deletions TopModel.Generator.Jpa/JpaModelPropertyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ private void WriteProperty(JavaWriter fw, Class classe, AssociationProperty prop
}
var suffix = string.Empty;
if (_config.CanClassUseEnums(property.Association, _classes, prop: property.Association.PrimaryKey.Single()))
if (property.Association.PrimaryKey.Count() == 1 && _config.CanClassUseEnums(property.Association, _classes, prop: property.Association.PrimaryKey.Single()))
{
var defaultValue = _config.GetValue(property, _classes);
if (defaultValue != "null")
Expand Down

0 comments on commit a7ec5b7

Please sign in to comment.