Model with references to anothers model. ¿It´s possible?

Model with references to anothers model. ¿It´s possible?

sicamansicaman Posts: 1Questions: 1Answers: 0

Hi!

Is it possible to make a selection in which a model that a reference to another model is selected?

Example:

public class Table1
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Table2 table2 { get; set; }
}

public class Table2
{
    public int Id { get; set; }
    public string Name { get; set; }
}

When I do the next code, I get "Invalid column name table2"

var response = new Editor(db, dbName, dbPKey)
.Model<Table1>("Table1")
.Model<Table2>("Table2")
.Field(new Field("Table1.table2")
.Options(new Options()
.Table("Table2")
.Value("Id")
.Label("Name "))
.Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
)
.LeftJoin("Table1", "Table1.table2", "=", "Table2.Id")
.TryCatch(false)
.Process(Request)
.Data();

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    No I'm afraid not - as the documentation notes:

    Please note that the model's data structure is used both for representation of the data from the database and the JSON data sent to the client-side for each row. This means that the data types used must be directly applicable to JSON as well as the database. In practice this means that string, int and Decimal are the data types that should be used. Other data forms such as DateTime fields should be given as a string, which Editor's libraries will convert automatically.

    You'd need to drop public Table2 table2 { get; set; } from your Table1 class.

    Allan

Sign In or Register to comment.