condition doesn't filter records

  • 1
  • Question
  • Updated 4 years ago
I'm working on writing some tests.... so I am writing a mock that can generate some records of the type I need to test

I added an is_Test__c field to the object I'm creating records for, its defaults to "unchecked"
When I create the records I pass an additional condition to set the value in the new record to true.

After I've created the 2 records I try to apply the condition that is_Test__c must be true to the model (which has the condition already... but the condition is set to default to "inactive") and then return the model from my function

what I find is that the 2 new records have been created... and their is_Test__c is set to true... but that all the other records in the model are returned as well... and not just the 2 I want

this.teacher_specialty_day = skuid.model.getModel('Cal_Teacher_Specialty_Day');    this.teacher_specialty_day_one = teacher_specialty_day.createRow(
        {
    additionalConditions: [
            { field: 'is_Test__c', value: true},
            { field: 'Cal_Teacher__c', value: this.teacher_object.Id},
            { field: 'Cal_Specialty__c', value: this.specialty_object.Id},
            { field: 'Cal_Day_Of_Week__c', value: this.day_of_week_one.Id}
            ], doAppend: true
        }
        );
    this.teacher_specialty_day_two = teacher_specialty_day.createRow(
        {
    additionalConditions: [
            { field: 'is_Test__c', value: true},
            { field: 'Cal_Teacher__c', value: this.teacher_object.Id},
            { field: 'Cal_Specialty__c', value: this.specialty_object.Id},
            { field: 'Cal_Day_Of_Week__c', value: this.day_of_week_two.Id}
            ], doAppend: true
        }
        );
     var test_condition = this.teacher_specialty_day.getConditionByName('is_Test__c');
    this.teacher_specialty_day.setCondition(test_condition,true);
    return this.teacher_specialty_day;

so if i inspect the returned value in the console I see
  1. 29: Object
    1. Cal_Day_Of_Week__c: "a4HU000000000xnMAA"
    2. Cal_Day_Of_Week__r: Object
    3. Cal_Specialty__c: "a4GU00000008foEMAQ"
    4. Cal_Specialty__r: Object
    5. Cal_Teacher__c: "a3aU00000001W7uIAE"
    6. Cal_Teacher__r: Object
    7. End_AM_PM__c: "a4NU00000004Kn5MAE"
    8. End_AM_PM__r: Object
    9. End_Hour__c: "a4MU00000004JMjMAM"
    10. End_Hour__r: Object
    11. End_Minute__c: "a4LU00000008QWBMA2"
    12. End_Minute__r: Object
    13. Id: "a4KU00000008QPuMAM"
    14. Id15: "a4KU00000008QPu"
    15. Start_AM_PM__c: "a4NU00000004Kn5MAE"
    16. Start_AM_PM__r: Object
    17. Start_Hour__c: "a4MU00000004JMpMAM"
    18. Start_Hour__r: Object
    19. Start_Minute__c: "a4LU00000008QW0MAM"
    20. Start_Minute__r: Object
    21. attributes: Object
    22. is_Test__c: false
    23. __proto__: Object
  2. 30: Object
    1. Cal_Day_Of_Week__c: "3"
    2. Cal_Specialty__c: "2"
    3. Cal_Teacher__c: "1"
    4. Id: "5"
    5. Id15: "5"
    6. is_Test__c: true
    7. __proto__: Object
  3. 31: Object
    1. Cal_Day_Of_Week__c: "4"
    2. Cal_Specialty__c: "2"
    3. Cal_Teacher__c: "1"
    4. Id: "6"
    5. Id15: "6"
    6. is_Test__c: true
    7. __proto__: Object
  4. length: 32
I don't understand why I see all the records


Photo of ktyler

ktyler

  • 9,244 Points 5k badge 2x thumb

Posted 4 years ago

  • 1
Photo of JD Bell

JD Bell, Senior Product Engineer

  • 2,996 Points 2k badge 2x thumb
Our updated API documentation, released just this week, addresses this point of confusion.

http://help.skuidify.com/m/11720/l/205447-skuid-model-model#SetCondition(Condition,Value,AffectCooki...

setCondition( ) turns the condition on, but does not immediately apply it. To apply it, you should call the updateData( ).

Note that updateData( ) will throw an error if there are unsaved changes in the Model, so you'll need to call save( ) on the Model (which will save your new records to the database) before calling updateData( ). I'm not sure if that's the behavior you were hoping for given that this is just a test.
(Edited)
Photo of ktyler

ktyler

  • 9,244 Points 5k badge 2x thumb
Well... I was hoping I could get away without saving... but that's why I put in the is_test field... i can just delete the test records after the test has run

Thanks for the help
Photo of JD Bell

JD Bell, Senior Product Engineer

  • 2,996 Points 2k badge 2x thumb
Ken, we are going to add the abandonRow( ) function to our documentation. You can use teacher_specialty_day.abandonRow( row ) to remove a row from a Model without deleting it. It'll be as if the row had never been fetched from the database in the first place. You could iterate over your Model and call this function for any rows where your is_test field is false.

There's also a corresponding removeRowById( id ) function that does the same thing, except you only need to pass in the row's Id.