Model created by StoreFor<> and multi HasManayAssociation Attribute

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Model created by StoreFor<> and multi HasManayAssociation Attribute

    I have a problem with HasManyAssociation Attribute.

    My sample has 7 classes, having associations with each other.

    School HasMany ClassRoom and Club

    ClassRoom HasMany Lecture and Facility

    Club HasMany Event and ClubLecture


    It's part of my sample...

    -- School Class
    This class has many ClassRooms and Clubs classes
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [HasManyAssociation(Model = "Test.school.ClassRoom", Name = "classRooms", PrimaryKey = "Id", AssociationKey = "ClassRooms", ForeignKey = "SchoolId")]
        [HasManyAssociation(Model = "Test.school.Club", Name = "clubs", PrimaryKey = "Id", AssociationKey = "Clubs", ForeignKey = "SchoolId")]
        [Model(Name = "Test.school.School")]
        public partial class School
        {
            public School()
            {
                this.ClassRooms = new HashSet<ClassRoom>();
                this.Clubs = new HashSet<Club>();
            }
    
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public string Name { get; set; }
            public string Location { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual ICollection<ClassRoom> ClassRooms { get; set; }
            public virtual ICollection<Club> Clubs { get; set; }
        }
    }
    -- ClassRoom Class
    This Class belongs to School class
    and has many Lectures and Facilities classes
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [HasManyAssociation(Model = "Test.school.Lecture", Name = "lectures", PrimaryKey = "Id", AssociationKey = "Lectures", ForeignKey = "ClassRoomId")]
        [HasManyAssociation(Model = "Test.school.Facility", Name = "facilities", PrimaryKey = "Id", AssociationKey = "Facilities", ForeignKey = "ClassRoomId")]
        [BelongsToAssociation(Model = "Test.school.School")]
        [Model(Name = "Test.school.ClassRoom")]
        public partial class ClassRoom
        {
            public ClassRoom()
            {
            }
    
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public int SchoolId { get; set; }
            public string Name { get; set; }
            public string Location { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual School School { get; set; }
        }
    }
    -- Club Class
    This class belongs to School class
    and has many Events and ClubLectures
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [HasManyAssociation(Model = "Test.school.ClubLecture", Name = "clubLectures", PrimaryKey = "Id", AssociationKey = "ClubLectures", ForeignKey = "ClubId"),
        HasManyAssociation(Model = "Test.school.Event", Name = "events", PrimaryKey = "Id", AssociationKey = "Events", ForeignKey = "ClubId")]
        [BelongsToAssociation(Model = "Test.school.School")]
        [Model(Name = "Test.school.Club")]
        public partial class Club
        {
            public Club()
            {
                this.ClubLectures = new HashSet<ClubLecture>();
                this.Events = new HashSet<Event>();
            }
    
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public int SchoolId { get; set; }
            public string Name { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual School School { get; set; }
            [ModelField(Ignore = true)]
            public virtual ICollection<ClubLecture> ClubLectures { get; set; }
            [ModelField(Ignore = true)]
            public virtual ICollection<Event> Events { get; set; }
        }
    }
    -- Facility Class
    This class belongs to ClassRoom class
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [BelongsToAssociation(Model = "Test.school.ClassRoom")]
        [Model(Name = "Test.school.Facility")]
        public partial class Facility
        {
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public int ClassRoomId { get; set; }
            public string Name { get; set; }
            public string Purpose { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual ClassRoom ClassRoom { get; set; }
        }
    }
    -- Lecture Class
    This class belongs to ClassRoom class
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [BelongsToAssociation(Model = "Test.school.ClassRoom")]
        [Model(Name = "Test.school.Lecture")]
        public partial class Lecture
        {
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public int ClassRoomId { get; set; }
            public string Name { get; set; }
            public string StartTime { get; set; }
            public string EndTime { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual ClassRoom ClassRoom { get; set; }
        }
    }
    -- Event Class
    This class belongs to Club class
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [BelongsToAssociation(Model = "Test.school.Club")]
        [Model(Name = "Test.school.Event")]
        public partial class Event
        {
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public int ClubId { get; set; }
            public string Name { get; set; }
            public Nullable<System.DateTime> StartDate { get; set; }
            public Nullable<System.DateTime> EndDate { get; set; }
            public string Description { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual Club Club { get; set; }
        }
    }
    -- ClubLecture Class
    This class belongs to Club class
    namespace Test.Models
    {
        using Ext.Net.MVC;
        using System;
        using System.Collections.Generic;
    
        [BelongsToAssociation(Model = "Test.school.Club")]
        [Model(Name = "Test.school.ClubLecture")]
        public partial class ClubLecture
        {
            [ModelField(IDProperty = true)]
            public int Id { get; set; }
            public int ClubId { get; set; }
            public string Name { get; set; }
            public Nullable<System.DateTime> StartDate { get; set; }
            public Nullable<System.DateTime> EndDate { get; set; }
            public Nullable<int> MaxMember { get; set; }
    
            [ModelField(Ignore = true)]
            public virtual Club Club { get; set; }
        }
    }
    -- part of cshtml
    I create client model with StoreFor<>
    
            Html.X().GridPanel()
            .ID("gvSchool")
            .AutoDestroy(true)
            .Width(500)
            .Height(50)
            .Hidden(false)
            .Store(
                Html.X().StoreFor<Test.Models.School>()
                .ID("storeSchool")
                .AutoDestroy(false)
                .Data(Model)
            )
    -- Created Javascript
    only one association defined
            items: [{
                store: {
                    model: Ext.define("Test.school.School", {
                        extend: "Ext.data.Model",
                        ns: "School",
                        fields: [{
                            name: "Id",
                            type: "int"
                        }, {
                            name: "Name",
                            type: "string"
                        }, {
                            name: "Location",
                            type: "string"
                        }, {
                            name: "Capacity",
                            type: "int"
                        }, {
                            name: "Area",
                            type: "float"
                        }, {
                            name: "Clubs"
                        }],
                        idProperty: "Id",
                        associations: [{
                            type: "hasMany",
                            associationKey: "ClassRooms",
                            primaryKey: "Id",
                            model: "Test.school.ClassRoom",
                            foreignKey: "SchoolId",
                            name: "classRooms"
                        }]
                    }),
                    storeId: "storeSchool",
                    ns: "School",
                    autoLoad: true,
                    data: {
                        "ClassRooms": [{
                            "Facilities": [],
                            "Lectures": [],
                            "Id": 1,
                            "SchoolId": 1,
                            "Name": "ClassRoom 1",
                            "Location": "1st floor - 1",
                            "Capacity": 50
                        }, {
                            "Facilities": [],
                            "Lectures": [],
                            "Id": 2,
                            "SchoolId": 1,
                            "Name": "ClassRoom 2",
                            "Location": "1st floor - 2",
                            "Capacity": 50
                        }],
                        "Clubs": [],
                        "Id": 1,
                        "Name": "School 1",
                        "Location": "Seoul",
                        "Capacity": 100,
                        "Area": 200.00
                    },
                    proxy: {
                        type: 'memory'
                    }
                },
                id: "gvSchool",
                ns: "School",
                height: 50,
                width: 500,
                xtype: "grid",
                columns: {
                    ns: "School",
                    items: [{
                        ns: "School",
                        xtype: "rownumberer",
                        align: "center"
                    }, {
                        ns: "School",
                        width: 70,
                        align: "center",
                        dataIndex: "Id",
                        text: "School Id"
                    }]
                }, ......
    -- part of Expected Javascript
    I expected two associations like below
                       associations: [{
                            type: "hasMany",
                            associationKey: "ClassRooms",
                            primaryKey: "Id",
                            model: "Test.school.ClassRoom",
                            foreignKey: "SchoolId",
                            name: "classRooms"
                        }, {
                           type: "hasMany",
                            associationKey: "Club",
                            primaryKey: "Id",
                            model: "Test.school.Club",
                            foreignKey: "SchoolId",
                            name: "clubs"
                        }]

    From definition AbstractAssociationAttribute in AbstractAssociationAttribute.cs file
    AllowMultiple = true

    HasManyAssociationAttribute inherit AbstractAssociationAttribute...

    Anything I missed?

    Thanks in advance ^^.
    Last edited by Daniil; Nov 13, 2013 at 11:45 AM. Reason: Aattribute => Attribute

Similar Threads

  1. Replies: 1
    Last Post: Jul 30, 2013, 3:36 PM
  2. [CLOSED] How to use StoreFor Model
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 18, 2012, 1:09 PM
  3. Replies: 0
    Last Post: Aug 01, 2012, 1:20 AM
  4. Replies: 2
    Last Post: Aug 09, 2011, 10:38 AM
  5. Multi Select - JIT
    By amitpareek in forum Open Discussions
    Replies: 1
    Last Post: Dec 09, 2008, 9:31 AM

Tags for this Thread

Posting Permissions