Oct 28, 2013, 1:15 AM
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
This Class belongs to School class
and has many Lectures and Facilities classes
This class belongs to School class
and has many Events and ClubLectures
This class belongs to ClassRoom class
This class belongs to ClassRoom class
This class belongs to Club class
This class belongs to Club class
I create client model with StoreFor<>
only one association defined
I expected two associations like below
From definition AbstractAssociationAttribute in AbstractAssociationAttribute.cs file
AllowMultiple = true
HasManyAssociationAttribute inherit AbstractAssociationAttribute...
Anything I missed?
Thanks in advance ^^.
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 ClassThis 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 ClassThis 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 ClassThis 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 ClassThis 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 ClassThis 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 ClassThis 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 cshtmlI 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 Javascriptonly 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 JavascriptI 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