.net mjoin example / models

.net mjoin example / models

montoyammontoyam Posts: 568Questions: 136Answers: 5
edited April 2020 in Free community support

In the link section in the mjoin manual: https://editor.datatables.net/manual/net/mjoin

the code given is this:

DtResponse response = new Editor(WebApiApplication.Db, "users")
    .Model<UserModel>()
    .MJoin(new MJoin("permission")
        .Link("users.id", "user_permission.user_id")
        .Link("permission.id", "user_permission.access_id")
        .Model<AccessModel>()
        .Order("permission.name")
        .Field(new Field("id")
            .Options("permission", "id", "name")
        )
    )
    .Process(formData)
    .Data();

it appears the model names are UserModel and AccessModel. However, below that code the models given appear to be named differently (StaffModel and PermissionsModel). I am struggling on using mjoin in my .net project and I think I may have my models built incorrectly. Trying to use the posted manual, I am not getting it.

public class StaffModel : EditorModel
{
    public class users : EditorModel
    {
        public string first_name { get; set; }
 
        public string role { get; set; }
    }
}

public class PermissionModel : EditorModel
{
    public string id { get; set; }
 
    public string name { get; set; }
}

I think it would help to see a sample of what the json would look like in these examples.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Hi,

    You are right, the manual is slightly different from the example. If you download the Editor .NET package you'll get all of the examples that are available on the Editor site, but written with backends for .NET.

    To help, this is the controller the example uses:

                    var response = new Editor(db, "users", "users.id")
                        .Debug(true)
                        .Model<JoinModelUsers>("users")
                        .Model<JoinModelSites>("sites")
                        .Field(new Field("users.site")
                            .Options(new Options()
                                .Table("sites")
                                .Value("id")
                                .Label("name")
                            )
                        )
                        .LeftJoin("sites", "sites.id", "=", "users.site")
                        .MJoin(new MJoin("permission")
                            .Link("users.id", "user_permission.user_id")
                            .Link("permission.id", "user_permission.permission_id")
                            .Model<JoinAccessModel>()
                            .Order("permission.name")
                            .Validator("permission[].id", Validation.MjoinMaxCount(4, "No more than four selections please"))
                            .Field(new Field("id")
                                .Options(new Options()
                                    .Table("permission")
                                    .Value("id")
                                    .Label("name")
                                )
                            )
                        )
                        .Process(Request)
                        .Data();
    

    This is the model used for the Mjoin:

        public class JoinAccessModel
        {
            public string id { get; set; }
    
            public string name { get; set; }
        }
    

    And the JSON response is the same as in the live PHP example.

    Allan

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    yeah, I guess jumping between the .net manual and php manual is a bit awkward, but you can get the whole picture doing that, including the javascript for the editor.

This discussion has been closed.