This commit is contained in:
2020-01-16 23:40:36 +00:00
parent d3cb9bea90
commit 54f90be425
4 changed files with 29 additions and 10 deletions

View File

@@ -40,7 +40,7 @@ namespace AyaNova.Models
{ {
// Replace table names // Replace table names
//entity.Relational().TableName = "a" + entity.Relational().TableName.ToLowerInvariant(); //entity.Relational().TableName = "a" + entity.Relational().TableName.ToLowerInvariant();
entity.SetTableName( "a" + entity.GetTableName().ToLowerInvariant()); entity.SetTableName("a" + entity.GetTableName().ToLowerInvariant());
// Replace column names // Replace column names
foreach (var property in entity.GetProperties()) foreach (var property in entity.GetProperties())
@@ -63,7 +63,7 @@ namespace AyaNova.Models
foreach (var key in entity.GetKeys()) foreach (var key in entity.GetKeys())
{ {
key.SetName(key.GetName().ToLowerInvariant()); key.SetName(key.GetName().ToLowerInvariant());
// key.Relational().Name = key.Relational().Name.ToLowerInvariant(); // key.Relational().Name = key.Relational().Name.ToLowerInvariant();
} }
foreach (var key in entity.GetForeignKeys()) foreach (var key in entity.GetForeignKeys())
@@ -95,6 +95,15 @@ namespace AyaNova.Models
.HasForeignKey<UserOptions>(b => b.UserId) .HasForeignKey<UserOptions>(b => b.UserId)
.OnDelete(DeleteBehavior.Cascade);//Hopefully will delete the useroptions with the user? .OnDelete(DeleteBehavior.Cascade);//Hopefully will delete the useroptions with the user?
//User->Widget this might be wrong
modelBuilder.Entity<User>()
.HasOne(p => p.Widget)
.WithOne(i => i.User)
.HasForeignKey<Widget>(b => b.UserId)
.OnDelete(DeleteBehavior.NoAction);
//----------- //-----------
} }

View File

@@ -44,6 +44,9 @@ namespace AyaNova.Models
[JsonIgnore]//hide from being returned (as null anyway) with User object in routes [JsonIgnore]//hide from being returned (as null anyway) with User object in routes
public UserOptions UserOptions { get; set; } public UserOptions UserOptions { get; set; }
[JsonIgnore]//hide from being returned (as null anyway) with User object in routes
public Widget Widget { get; set; }
public User() public User()
{ {
Tags = new List<string>(); Tags = new List<string>();

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using AyaNova.Biz; using AyaNova.Biz;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace AyaNova.Models namespace AyaNova.Models
{ {
@@ -26,6 +26,12 @@ namespace AyaNova.Models
public int? Count { get; set; } public int? Count { get; set; }
public string CustomFields { get; set; } public string CustomFields { get; set; }
public List<string> Tags { get; set; } public List<string> Tags { get; set; }
//relations
//https://docs.microsoft.com/en-us/ef/core/modeling/relationships#other-relationship-patterns
[JsonIgnore]//hide from being returned (as null anyway) with User object in routes
public User User { get; set; }
[Required]
public long UserId { get; set; }
public Widget() public Widget()
{ {

View File

@@ -209,7 +209,8 @@ namespace AyaNova.Util
//Add widget table //Add widget table
//id, text, longtext, boolean, currency, //id, text, longtext, boolean, currency,
exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, serial bigint not null," + exec("CREATE TABLE awidget (id BIGSERIAL PRIMARY KEY, name varchar(255) not null, serial bigint not null," +
"startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, count integer, notes text, customfields text, tags varchar(255) ARRAY)"); "startdate timestamp, enddate timestamp, dollaramount decimal(19,5), active bool, roles int4, count integer,"+
"notes text, userid bigint, customfields text, tags varchar(255) ARRAY)");
//TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS //TEST TEST TEST ONLY FOR DEVELOPMENT TESTING TO ENSURE UNIQUENESS
//exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);"); //exec("CREATE UNIQUE INDEX awidget_serial_idx ON awidget (serial);");