Skip to content

Getting value nill after mapping  #129

@krishnasolankiBigbang

Description

@krishnasolankiBigbang

class of mapping is ::
class XYZSetting: NSManagedObject {

var address_id:NSNumber!
var client_name:String!
var clientvendorid:NSNumber!
var company_id:NSNumber!
var location_type:NSNumber!
var modified_by:NSNumber!
var user_id:NSNumber!
var userlocationtype:NSNumber!
var clientaddress:AddressList?


class func entityName()->String{
    return "XYZSetting"
}

class func defaultMapping()->FEMMapping{
    let mapping = FEMMapping.init(entityName: self.entityName())
    mapping.addAttribute(Mapping.intAttributeFor(property: "user_id", keyPath: "UserID"))
    //mapping.addAttribute(Mapping.intAttributeFor(property: <#T##String#>, keyPath: <#T##String#>))
    mapping.addAttribute(Mapping.intAttributeFor(property: "company_id", keyPath: "CompanyID"))
    mapping.addAttribute(Mapping.intAttributeFor(property: "address_id", keyPath: "AddressID"))
    mapping.addAttribute(Mapping.intAttributeFor(property: "clientvendorid", keyPath: "ClientVendorID"))
     mapping.addAttribute(Mapping.intAttributeFor(property: "location_type", keyPath: "LocationType"))
    mapping.addAttribute(Mapping.intAttributeFor(property: "modified_by", keyPath: "ModifiedBy"))
    mapping.addAttribute(Mapping.intAttributeFor(property: "user_location_type", keyPath: "UserLocationType"))
    mapping.addAttributes(from: ["client_name":"ClientName"])
mapping.addRelationshipMapping(AddressList.defaultmapping(), forProperty: "clientaddress", keyPath: "ClientAddress")
    mapping.primaryKey = "clientvendorid"
    return mapping
}
class func getAll()->[DefaultSetting]{
    return XYZSetting.mr_findAll() as? [XYZSetting] ?? [XYZSetting]()
}
class func getDefaultSetting()->XYZSetting?{

    if let dsetting = XYZSetting.mr_findFirst(in: NSManagedObjectContext.mr_default()) as? XYZSetting{ 
       {
        if let defaultsetting = XYZSetting.mr_findAll()?.first as? DefaultSetting{
            print("address id = \(defaultsetting.address_id)")
            //print(defaultsetting.userid)
            print("Location  type = \(defaultsetting.location_type)")
            }
        print("location type in model  = \(dsetting.location_type)")
       return dsetting
    }

else{
return nil
}
}
}

code for mapping is ::

MagicalRecord.save({ (localcontext) in
XYZSetting.mr_truncateAll(in: localcontext)
print("count of default setting is = (XYZSetting.getAll().count)")
let arr = FEMDeserializer.collection(fromRepresentation: [dic], mapping: XYZSetting.defaultMapping(), context: localcontext)
print("setting arr = (arr)")
print("count of default setting after mapping (XYZSetting.getAll().count)")

localcontext.mr_save({ (localcontext) in
print("saving")
}, completion: { (status, error) in
print("status = (status)")
print("saved")
print("get default setting (XYZSetting.getDefaultSetting())")
print("Location type using default = (XYZSetting.getDefaultSetting()?.location_type)")
if let defaultsetting = XYZSetting.mr_findAll()?.first as? DefaultSetting{
print("address id = (defaultsetting.address_id)")
//print(defaultsetting.userid)
print("Location type = (defaultsetting.location_type)")
}
})

Getting log is this ::
"
count of default setting is = 1
setting arr = [<DefaultSetting: 0x600000e28a00> (entity: DefaultSetting; id: 0x600003f44d80 x-coredata:///DefaultSetting/t1E3B2DA0-7EED-4FE9-B738-B4630920C75D2; data: {
"address_id" = 0;
"client_name" = nil;
clientaddress = "0x96cd7ec8fb807514 x-coredata://AEB29A34-BE29-4A08-9966-E497846108D9/AddressList/p318";
clientvendorid = 0;
"company_id" = 1604;
"location_type" = 4;
"modified_by" = 0;
"user_id" = 12973;
"user_location_type" = 1;
})]
count of default setting after mapping 1
2020-12-10 11:43:28.442586+0530 SuperSales[15152:97995] Created new private queue context: <NSManagedObjectContext: 0x60000047c000>
saving
2020-12-10 11:43:28.443971+0530 SuperSales[15152:97995] → Saving <NSManagedObjectContext (0x60000047d860): saveWithBlock:completion:> on a background thread
status = false
saved
address id = nil
Location type in dafault setting = nil
location type in model = nil
get default setting Optional(<DefaultSetting: 0x600000e34d20> (entity: DefaultSetting; id: 0x96cd7ec8ff707516 x-coredata://AEB29A34-BE29-4A08-9966-E497846108D9/DefaultSetting/p2; data: ))
address id = nil
Location type in dafault setting = nil
location type in model = nil
Location type using default = nil
address id = nil
Location type = nil

"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions