Datos básicos y funcionalidad 'me gusta' entre entidades

I'm about to implement a como functionality between a User entity and some other entity, such that User A can como an entity X. However, I'm not sure how to best implement this in Core Data.

There are two main points I need to consider:

  • Añadiendo otro simpático entity should be trivial
  • There needs to be a way to sync a Like that has been performed offline

My initial thought was to create an resumen Core Data entity Like.

A User tiene una relación de muchos con Like, Y un Like Tiene uno User.

Then for each entity that should be simpático, I create a subclass of Like that has a to-one relationship to the simpático entity. The relationship to the User se hereda.

This way, the abstract entity Like can have attributes such as "syncedAt" and "deletedAt" so that it's possible to find out if a Like type entity has been synced to the server or not.

Does this sound reasonable or are there better ways to solve this problem in Core Data? Are there disadvantages to this design that I'm not foreseeing?

preguntado el 01 de febrero de 12 a las 14:02

1 Respuestas

why not have a parent entity LikableEntity which your likable entityies inherit from: this could have the synchedAt attributes. The your User has a to-many relationship likedEntities which contains anything it has liked

Respondido 01 Feb 12, 18:02

I've thought about this as well. But there are some issues. I won't know what's unsynced with the entity, i.e. which specific 'like' that needs to be POSTed to the server. And also, the likable entities may already be inheriting from another class that should not be likable. - hwaxxer

I think you could use a predicate for the first one: synchedAt == nil (or is older than some stale timeout)? For the second if you had your other class as the root, the LikableEntity inherits from it, then your class inherits from LikableEntity. So the root class is not likeable, but your class is? - wattson12

Using a predicate still doesn't solve the case in knowing exactly what changed and what needs syncing, did the object change or did some relationship to it change etc? And letting the LikableEntity inherit from some other entity seems a bit icky. What if I need to make another likeable that inherits from some other entity? - hwaxxer

yeah i agree its not great having multiple entities in the inheritance, was just trying to think of alternatives to a proxy type entity. for the first one you would need to implement that logic anyway wouldnt you? - wattson12

Making the 'like' a proxy type entity is a bit awkward, I agree. But it seems like the easiest way to later keep track of syncing. Maybe the benefits of making it a proxy type object outweighs the cost of a cleaner, direct relationship-type. - hwaxxer

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.