Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, I would check that the relationship is set from the other side by logging <code>self.session</code>. If that shows as null then you have no reciprocal relationship set in the model.</p> <p>I think that your fetch is poorly constructed. You are relying on the sort descriptor to provide the last used session but you only have a fetch limit of 1. You seem to think that the fetch will find all existing <code>Session</code> objects, sort them and then return the first one. However, sorts execute last so the fetch will find a single session object (because of the fetch limit) and will then apply the sort to that single object. This makes it likely that you will be dealing with a more or less random <code>Session</code> object. </p> <p>You probably don't need a fetch at all because you are only interested in the <code>Session</code> objects in a relationship with the <code>User</code> object which is <code>self</code>. If you already have the object in one side of a relationship, you don't need to fetch, you just need to walk the relationship. All you really need to do is:</p> <pre><code>if ([self.session count]==0){ //...create new session and set relationship }else{ //... find latest session } </code></pre> <p>I think your problem with this particular chunk of code is in the reporting. When you get a return value, you use the <code>self.user</code> notation but where you get a <code>null</code> return you use <code>valueForKey:</code>. </p> <p>While in theory both return the same value, they don't have to because they don't use the same mechanism to return the value. The self-dot notation calls an accessor method while <code>valueForKey:</code> may or may not depending on the specifics of a class' implementation. I would test if the <code>self.session</code> returns a value where <code>valueForKey:</code> does not. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload