According to your requirement, you do not want to share via role hierarchy. Because if that is shared then any user can see subordinate's data irrespective of Manager's name defined in the user.
Just to let you know, Manager's name in the User is not related to data visibility. This field is especially useful for creating hierarchical workflow rules and approval processes without creating more hierarchy fields.
Here sometimes criteria based sharing rule does not fit into your requirement. Because, it may possible you want show subordinate's all data to his manager only.
Approach will be
do not select Grant Access using Role Hierarchy for this object in Sharing Settings.
Creating User Managed Sharing Using Apex. Refer Sharing a Record Using Apex for more information.
After record is created, then call this method and pass the userOrGroupId
taking value from your User's Manager field.
If you want that the manager will get All types of access then use Force.com managed sharing.
Otherwise access can be Edit, Read.
Below is the code snippet as to how data can be shared.
Apex code
public class JobSharing {
public static boolean manualShareRead(Id recordId, Id userOrGroupId){
// Create new sharing object for the custom object Job.
Job__Share jobShr = new Job__Share();
// Set the ID of record being shared.
jobShr.ParentId = recordId;
// Set the ID of user or group being granted access.
jobShr.UserOrGroupId = userOrGroupId;
// Set the access level.
jobShr.AccessLevel = 'Read';
// Set rowCause to 'manual' for manual sharing.
// This line can be omitted as 'manual' is the default value for sharing objects.
jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
// Insert the sharing record and capture the save result.
// The false parameter allows for partial processing if multiple records passed
// into the operation.
Database.SaveResult sr = Database.insert(jobShr,false);
// Process the save results.
if(sr.isSuccess()){
// Indicates success
return true;
}
else {
// Get first save result error.
Database.Error err = sr.getErrors()[0];
// Check if the error is related to trival access level.
// Access level must be more permissive than the object's default.
// These sharing records are not required and thus an insert exception is acceptable.
if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION &&
err.getMessage().contains('AccessLevel')){
// Indicates success.
return true;
}
else{
// Indicates failure.
return false;
}
}
}
}