mikeedwards83 / Glass.Mapper

Version 5 of the Glass mapping framework, the best ORM for Sitecore.
Apache License 2.0
124 stars 122 forks source link

Properties of type Image being instantiated when NULL in Sitecore #142

Closed drachele closed 9 years ago

drachele commented 9 years ago

I have a class with a property of type Glass.Mapper.Sc.Fields.Image, and even if there is no value set in Sitecore, this property is being returned from Glass as an instance of Image, with empty values and an empty ID.

This is my domain model class:

[SitecoreType(TemplateId = Constants.Templates.IdStrings.ImageWithBoxedTextModule, AutoMap = true)]
    public class ImageWithBoxedTextModule : ModuleBase
    {
        public virtual Image Image { get; set; }
        public virtual string Caption { get; set; }
        public virtual string Heading { get; set; }
        public virtual string SubHeading { get; set; }
        public virtual string HeadingTextSize { get; set; }
        public virtual string Body { get; set; }
    }

I'm using the latest version (4.0.1.5). I've used version 3 in the past, and if there was no value set on the property, it would set as NULL, which is what I would expect in this version as well. In order to determine if an image is available, I now need to add extra code to check the ID of the Image property to check if the ID is something other than Guid.Empty.

Is this expected behaviour in the new version, or a bug?

Or am I missing something obvious?

Thanks, Dan.

mikeedwards83 commented 9 years ago

Hi

If i have an empty field I get Null for the image. Could you see if there is a value in the field in Raw values mode?

Thanks

Mike

drachele commented 9 years ago

Hi Mike,

Viewing raw values in Sitecore, the field for the image is definitely empty.

Cheers, Dan.

mikeedwards83 commented 9 years ago

What Sitecore version are you using?

On Thu, 18 Jun 2015 02:53 Daniel Rachele notifications@github.com wrote:

Hi Mike,

Viewing raw values in Sitecore, the field for the image is definitely empty.

Cheers, Dan.

— Reply to this email directly or view it on GitHub https://github.com/mikeedwards83/Glass.Mapper/issues/142#issuecomment-113009362 .

drachele commented 9 years ago

Sitecore.NET 7.2 (rev. 140526)

drachele commented 9 years ago

I'm also having the same issue with the File type. Src is null and the ID is Guid.Empty.

mikeedwards83 commented 9 years ago

Are you still having this problem? I am still not able to replicate this.

drachele commented 9 years ago

Afraid so.

Is there any more information I could provide you with to try and replicate the issue?

vasiliyfomichev commented 9 years ago

Hey Mike,

I have just installed Sitecore 7.2 update 4 to check this and was able to replicate the same behavior. I added an image field to the default /sitecore/content/home item and added a test sublayout. Here is a link to my quick prototype project in web forms http://www.cmsbestpractices.com/GlassTest.zip

mikeedwards83 commented 9 years ago

Ok I have replicated and push a fix to develop. Could you download the latest nightly build 4.0.1.35

mikeedwards83 commented 9 years ago

fixed in 4.0.2