Nested composite element

nichols.mike.s's Avatar

nichols.mike.s

26 May, 2010 05:51 PM via web

The 'name' attribute is not getting set on the nested-composite-element...I presume because it is using the same logic as a Component which doesn't require that attribute.

I have tried some things to get it to apply the name but get lost in the maze of visitors.

Can a workaround be suggested?

  1. 2 Posted by nichols.mike.s on 26 May, 2010 06:43 PM

    nichols.mike.s's Avatar

    K..got this to pass inside the OneToManyTester, adding a nested component on the component. I am sprinting so no time to clone/patch/pull-request...will do soon:

     [Test]
        public void ShouldMapElementsOfCompositeElementWithNestedCompositeElement()
        {
            new MappingTester<OneToManyComponentTarget>()
                .ForMapping(m => m.HasMany(x => x.SetOfComponents)
                                     .Component(c => c.Component(x => x.Inner, inner => inner.Map(it => it.Name))))
                .Element("class/set/composite-element/nested-composite-element").HasAttribute("name", "Inner");
        }
    

    Changed inside XmlCompositeElementWriter:

    public override void ProcessCompositeElement(CompositeElementMapping mapping)
        {
            document = new XmlDocument();
    
            var name = mapping is NestedCompositeElementMapping ? "nested-composite-element" : "composite-element";
            var element = document.AddElement(name);
    
            if (mapping.HasValue(x => x.Class))
                element.WithAtt("class", mapping.Class);
    
            if (mapping is NestedCompositeElementMapping)
                element.WithAtt("name", ((NestedCompositeElementMapping) mapping).Name);
        }
    
  2. Support Staff 3 Posted by Paul Batum on 30 May, 2010 10:23 AM

    Paul Batum's Avatar

    Hi Mike,

    I've applied your fix to my repository. I couldn't quite get your test to
    compile but I wanted to write a lower level one anyway so I did so. Your fix
    should be in the official trunk in a week or so.

    Thanks!

  3. 4 Posted by nichols.mike.s on 30 May, 2010 04:24 PM

    nichols.mike.s's Avatar

    Wow Paul thanks! I was planning on contributing a patch the formal way soon
    but you beat me to it.
    I have another bug I need to patch so I'll try to contribute that soon.
    Collections of components are trying to be mapped as collections of entities
    (FNH isn't applying the IsComponent rule to ChildType's) so one is required
    to do an override for every entity that has those.

    // Add your reply above here

  4. Support Staff 5 Posted by Paul Batum on 31 May, 2010 10:37 AM

    Paul Batum's Avatar

    Cool, send me a pull request when you've made your other change! Cheers.

  5. Paul Batum resolved this discussion on 31 May, 2010 10:37 AM.

Comments are currently closed for this discussion. You can start a new one.