Updated macro repo and services and ensures correct data joins

This commit is contained in:
Shannon
2013-09-17 20:19:27 +10:00
parent 89f2c0e38f
commit 75c913cced
11 changed files with 276 additions and 95 deletions

View File

@@ -0,0 +1,47 @@
using System.Collections.Generic;
using Umbraco.Core.Models.Rdbms;
namespace Umbraco.Core.Persistence.Relators
{
internal class MacroPropertyRelator
{
internal MacroDto Current;
internal MacroDto Map(MacroDto a, MacroPropertyDto p)
{
// Terminating call. Since we can return null from this function
// we need to be ready for PetaPoco to callback later with null
// parameters
if (a == null)
return Current;
// Is this the same DictionaryItem as the current one we're processing
if (Current != null && Current.Id == a.Id)
{
// Yes, just add this MacroPropertyDtos to the current item's collection
Current.MacroPropertyDtos.Add(p);
// Return null to indicate we're not done with this Macro yet
return null;
}
// This is a different Macro to the current one, or this is the
// first time through and we don't have one yet
// Save the current Macro
var prev = Current;
// Setup the new current Macro
Current = a;
Current.MacroPropertyDtos = new List<MacroPropertyDto>();
//this can be null since we are doing a left join
if (p.Alias != null)
{
Current.MacroPropertyDtos.Add(p);
}
// Return the now populated previous Macro (or null if first time through)
return prev;
}
}
}