EVReflection icon indicating copy to clipboard operation
EVReflection copied to clipboard

Property mapping is not called

Open amgadserry opened this issue 7 years ago • 2 comments
trafficstars


public class Address: EVManagedObject {
    
    override public func propertyMapping() -> [(keyInObject: String?, keyInResource: String?)] {
        return [
            (keyInObject: "firstName",keyInResource: "first_name"),
            (keyInObject: "lastName",keyInResource: "last_name"),
            (keyInObject: "address1",keyInResource: "address_1"),
            (keyInObject: "address2",keyInResource: "address_2")
        ]
    }
    
    func updateRemote(onSuccess: @escaping ()->(), onFailure: @escaping ()->()) throws{
        if let user = User.current {
            let url = "\(API.addressUrl)/\(user.id)"
            let data: [String: Any] = self.toDictionary() as! [String : Any]
            Alamofire.request(url, method: .post, parameters: data).validate().responseString(completionHandler: { response in
                switch response.result {
                    case .success:
                        if let oldAddress = user.shippingAddress {
                            oldAddress.mr_deleteEntity(in: AppDelegate.getContext())
                        }
                        user.shippingAddress = self
                        try! AppDelegate.getContext().save()
                        onSuccess()
                    case .failure( _):
                        onFailure()
                }
            })
        } else {
            throw AddressErrors.noUserFound
        }
    }
}
   

self.toDictionary doesn't cause property mapping to be called

amgadserry avatar Feb 03 '18 10:02 amgadserry

    open func toDictionary(_ conversionOptions: ConversionOptions = .DefaultSerialize) -> NSDictionary {
        let keys = Array(self.entity.attributesByName.keys)
        return self.dictionaryWithValues(forKeys: keys) as NSDictionary
    }

as I see here conversionOptions are ignored and the dictionaryWithValues used anyways @evermeer is that the intended behavior if not i could look into fixing it and make a PR

amgadserry avatar Feb 03 '18 11:02 amgadserry

Ah, you are right, this is something I did not implement for CoreData. It would be awesome If you could make a pull request for this.

evermeer avatar Feb 03 '18 14:02 evermeer