Code Monkey home page Code Monkey logo

Comments (7)

loganm avatar loganm commented on August 14, 2024

Looks like it doesn't, as per the following unit test. I'll have a play and see if I can make something work.

I'm thinking, because reflective lookups can't be required, the UnitOfWork could do two DML passes on those records. One to insert them and get Ids, and another to backfill the reflective lookups and update if required.

@IsTest
private static void reflectiveLookups()
{
    fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
    Product_Category__c productCategory1 = TestObjectFactory.createProductCategory( uow );
    Product_Category__c productCategory2 = TestObjectFactory.createProductCategory( uow, productCategory1 );
    Product_Category__c productCategory3 = TestObjectFactory.createProductCategory( uow, productCategory2 );
    uow.commitWork();
    productCategory1 = [SELECT Id, Parent_Category__c FROM Product_Category__c WHERE Id = :productCategory1.Id];
    productCategory2 = [SELECT Id, Parent_Category__c FROM Product_Category__c WHERE Id = :productCategory2.Id];
    productCategory3 = [SELECT Id, Parent_Category__c FROM Product_Category__c WHERE Id = :productCategory3.Id];
    System.assertEquals(null, productCategory1.Parent_Category__c);
    System.assertEquals(productCategory1.Id, productCategory2.Parent_Category__c, 'The category should be related to a parent category');
    System.assertEquals(productCategory2.Id, productCategory3.Parent_Category__c, 'The category should be related to a parent category');
}

System.AssertException: Assertion Failed: The category should be related to a parent category: Expected: a0KO0000004aLS0MAM, Actual: null

from fflib-apex-common.

loganm avatar loganm commented on August 14, 2024

@afawcett I've added support for reflective lookups to my fork. Can you turn this into a feature request, and I'll do a pull request for review.

from fflib-apex-common.

afawcett avatar afawcett commented on August 14, 2024

It's maybe because its been quite a long week, but can you elaborate more on what a 'reflective lookup' is?

from fflib-apex-common.

loganm avatar loganm commented on August 14, 2024

Phew, tough sprint. Finally got some head space back.

By reflective lookup, I mean a self lookup, or a self relationship. A lookup that points to the same SObjectType on which it's created.

I've patched my fflib fork to handle self lookups and it's working well. Sure there is a performance hit, but I've found doing an insert followed by an update is much friendlier than trying to chain DML inserts within an SObjectType.

from fflib-apex-common.

afawcett avatar afawcett commented on August 14, 2024

Thanks @loganm, sounds interesting, looking forward to taking a look at this.

In the meantime have you seen this long standard PR from @adtennant?

#23

from fflib-apex-common.

loganm avatar loganm commented on August 14, 2024

My solution for cyclic dependancies has been in play on my org for a while now, and hasn't spat the dummy once. So I'll open a pull request of its current state for review.

from fflib-apex-common.

daveespo avatar daveespo commented on August 14, 2024

I don't know if this is still true .. please reopen with a repro case if so

from fflib-apex-common.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.