Skip to content

Commit df3c859

Browse files
committed
Include Reference Only issue resolve
1 parent 88f621f commit df3c859

3 files changed

Lines changed: 94 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### Version: 2.7.1
2+
#### Date: Jan-11-2021
3+
4+
##### Bug fix:
5+
- Live preview Query issue
6+
17
### Version: 2.7.0
28
#### Date: Oct-14-2021
39

Contentstack.Core/Models/Entry.cs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -983,20 +983,18 @@ public Entry IncludeReference(String[] referenceFields)
983983
/// </example>
984984
public Entry IncludeOnlyReference(string[] keys, string referenceKey)
985985
{
986-
List<string> objectUidForOnly = new List<string>();
987-
Dictionary<string, object> onlyValueJson = new Dictionary<string, object>();
988986
if (keys != null && keys.Length > 0)
989987
{
990-
991-
int count = keys.Length;
992-
for (int i = 0; i < count; i++)
993-
{
994-
objectUidForOnly.Add(keys[i]);
988+
var referenceKeys = new string[] { referenceKey };
989+
if (UrlQueries.ContainsKey("include[]") == false)
990+
{
991+
UrlQueries.Add("", referenceKeys);
992+
993+
}
994+
if (UrlQueries.ContainsKey($"only[{referenceKey}][]") == false)
995+
{
996+
UrlQueries.Add($"only[{referenceKey}][]", keys);
995997
}
996-
onlyValueJson.Add(referenceKey, objectUidForOnly);
997-
UrlQueries.Add("include", new object[] { referenceKey });
998-
UrlQueries.Add("only", onlyValueJson);
999-
1000998
}
1001999

10021000
return this;
@@ -1184,22 +1182,20 @@ public Entry IncludeOwner()
11841182
/// </example>
11851183
public Entry IncludeExceptReference(string[] keys, string referenceKey)
11861184
{
1187-
List<string> objectUidForOnly = new List<string>();
1188-
Dictionary<string, object> onlyValueJson = new Dictionary<string, object>();
1185+
11891186
if (keys != null && keys.Length > 0)
11901187
{
1191-
1192-
int count = keys.Length;
1193-
for (int i = 0; i < count; i++)
1194-
{
1195-
objectUidForOnly.Add(keys[i]);
1188+
var referenceKeys = new string[] { referenceKey };
1189+
if (UrlQueries.ContainsKey("include[]") == false)
1190+
{
1191+
UrlQueries.Add("include[]", referenceKeys);
1192+
1193+
}
1194+
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
1195+
{
1196+
UrlQueries.Add($"except[{referenceKey}][]", keys);
11961197
}
1197-
onlyValueJson.Add(referenceKey, objectUidForOnly);
1198-
UrlQueries.Add("include", new object[] { referenceKey });
1199-
UrlQueries.Add("except", onlyValueJson);
1200-
12011198
}
1202-
12031199
return this;
12041200
}
12051201

Contentstack.Core/Models/Query.cs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,9 +1212,43 @@ public Query Only(String[] fieldUid)
12121212
Console.WriteLine("IOException source: {0}", e.Source);
12131213
}
12141214

1215+
return this;
1216+
}
1217+
1218+
/// <summary>
1219+
/// Specifies an array of only keys that would be included in the response.
1220+
/// </summary>
1221+
/// <param name="keys">Array of the only reference keys to be included in response.</param>
1222+
/// <param name="referenceKey">Key who has reference to some other class object.</param>
1223+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
1224+
/// <example>
1225+
/// <code>
1226+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
1227+
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
1228+
///
1229+
/// csQuery.IncludeOnlyReference(new String[]{&quot;name&quot;, &quot;description&quot;}, &quot;referenceUid&quot;);
1230+
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
1231+
/// //Your callback code.
1232+
/// });
1233+
/// </code>
1234+
/// </example>
1235+
public Query IncludeOnlyReference(string[] keys, string referenceKey)
1236+
{
1237+
if (keys != null && keys.Length > 0)
1238+
{
1239+
var referenceKeys = new string[] { referenceKey };
1240+
if (UrlQueries.ContainsKey("include[]") == false)
1241+
{
1242+
UrlQueries.Add("include[]", referenceKeys);
1243+
1244+
}
1245+
if (UrlQueries.ContainsKey($"only[{ referenceKey}][]") == false)
1246+
{
1247+
UrlQueries.Add($"only[{referenceKey}][]", keys);
1248+
}
1249+
}
12151250
return this;
12161251
}
1217-
12181252
/// <summary>
12191253
/// Specifies list of field uids that would be excluded from the response.
12201254
/// </summary>
@@ -1249,6 +1283,40 @@ public Query Except(String[] fieldUids)
12491283
return this;
12501284
}
12511285

1286+
/// <summary>
1287+
/// Specifies an array of except keys that would be excluded in the response.
1288+
/// </summary>
1289+
/// <param name="keys">Array of the except reference keys to be excluded in response.</param>
1290+
/// <param name="referenceKey">Key who has reference to some other class object.</param>
1291+
/// <returns>Current instance of Entry, this will be useful for a chaining calls.</returns>
1292+
/// <example>
1293+
/// <code>
1294+
/// ContentstackClient stack = new ContentstackClinet(&quot;api_key&quot;, &quot;delivery_token&quot;, &quot;environment&quot;);
1295+
/// Query csQuery = stack.ContentType(&quot;contentType_id&quot;).Query();
1296+
/// csQuery.IncludeExceptReference(new String[]{&quot;name&quot;, &quot;description&quot;},&quot;referenceUid&quot;);
1297+
/// csQuery.Find&lt;Product&gt;().ContinueWith((queryResult) =&gt; {
1298+
/// //Your callback code.
1299+
/// });
1300+
/// </code>
1301+
/// </example>
1302+
public Query IncludeExceptReference(string[] keys, string referenceKey)
1303+
{
1304+
if (keys != null && keys.Length > 0)
1305+
{
1306+
var referenceKeys = new string[] { referenceKey };
1307+
if (UrlQueries.ContainsKey("include[]") == false)
1308+
{
1309+
UrlQueries.Add("include[]", referenceKeys);
1310+
1311+
}
1312+
if (UrlQueries.ContainsKey($"except[{ referenceKey}][]") == false)
1313+
{
1314+
UrlQueries.Add($"except[{referenceKey}][]", keys);
1315+
}
1316+
}
1317+
return this;
1318+
}
1319+
12521320
/// <summary>
12531321
/// Include fallback locale publish content, if specified locale content is not publish.
12541322
/// </summary>

0 commit comments

Comments
 (0)