Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the LBModelRepository to allow filter responses with the inc… #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jpswensen
Copy link

@jpswensen jpswensen commented Jun 26, 2016

…lude filter to interpret arrays correctly.

I was trying to find a way to have the loopback-sdk-ios automatically include an NSArray of the appropriate model type when there was a filter request that had the "include" filter for a set of models with a hasMany relation. The attached pull request modifies the LBModelRepository to keep a global dictionary of the various repository objects and a modification of the modelWithDictionary to handle requests that have arrays of other model types.

Example usage:
(1) Create a model that not only has its own fields, but also an optional array that allows for the "include" filter:

(Swift code)
class Customer : LBPersistedModel {
    var id: NSNumber!
    var customer_name: String!
    var customer_location_id: NSNumber!
    var user_closet_items: [Order]? = nil
}

class Order : LBPersistedModel {
  var id: NSNumber!
  var customer_id: NSNumber!
  var order_name: String!
}

(2) Create a CustomerRepository object and a OrderRepository object so that they are both known to the new global repositoryDictionary

(3) Execute a findWithFilter that includes a "include" filter

// Retrieve a limited list with includes
        AppDelegate.customerRepository.findWithFilter(["where":["id":3],"include":"orders"], success: { (objectList:[AnyObject]!) in
            print(objectList)

        }) { (err:NSError!) in
            print(err)
        }

(4) The objectList in Step (3) is a Customer model object that has the "orders" array populated with the associated orders. If the user had just done a query without the "include" filter then the "order" variable in the Customer model would have remained nil.

@slnode
Copy link

slnode commented Jun 26, 2016

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@slnode
Copy link

slnode commented Jun 26, 2016

Can one of the admins verify this patch?

…e reason, none of the nested Dictionary objects were doing queries correctly for AND and OR operations on WHERE. Adding this method allows me to test all filters using cURL and then use the exact same query string from within my application.
@slnode
Copy link

slnode commented Sep 9, 2016

Can one of the admins verify this patch?

@jpswensen
Copy link
Author

Any update on whether this is acceptable? I can keep working off my own branch. I also just realized that another commit (related to filtering, but not nested JSON lists from include filters) also showed up in this pull request. I haven't used github pull requests much. I guess I should have made another branch to work off of for the second patch.

@bajtos
Copy link
Contributor

bajtos commented Sep 20, 2016

@gunjpan @jannyHou could you PTAL?

@gunjpan
Copy link

gunjpan commented Oct 14, 2016

@jpswensen : Hi, could you please rebase your PR against the master and push so that I can get CI running. Thank you.

@slnode
Copy link

slnode commented Oct 14, 2016

Can one of the admins verify this patch?

@gunjpan gunjpan removed their assignment Dec 9, 2016
@siddhipai siddhipai removed the triage label Mar 31, 2017
@bajtos
Copy link
Contributor

bajtos commented Jan 5, 2018

@jpswensen I am afraid we are no longer actively maintaining the project. Would you perhaps like to step up to become a maintainer yourself? If yes, then please leave a comment in #136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants