sorting - CoreData maintain relationship order -


i have simple coredata model expressed as:

enter image description here

there number of "trips" can contain multiple images. additionally, single image can in multiple trips.

my issue want maintain order in added trip. normally, add field imagedata object maintains index. however, because image can in number of trips doesn't make sense.

what clean way maintaining index in case?

the old way of handling provide linking entity encodes order.

trip{   //...various attributes   images<-->>triptoimage.trip }  image{   //...various attributes   trips<-->>triptoimage.image }  triptoimage{   trip<<-->trip.images   image<<-->image.trips   previous<-->triptoimage.next   next<-->triptoimage.previous } 

the linking entity extending modeling of relationship. can create arbitary order of trips or images.

however, such ordering can rendered superfluous better model design. in case, if images have specific dates , locations, how can part of more 1 trip? modeling time traveling agency? ;-)

core data should simulate/model real-world objects, events , conditions app deals with. real-world images , trips have attributes uniquely describe them in space , time. if entities accurately capture data, ordering them based on attributes becomes trivial.

usually, need use linking entity when have model arbitrary order such user's favorite ranking or other subjective ordering.

update:

it takes images of places you'd see , put them in list trip. i.e. not images have taken.

your current model cumbersome because not modeling problem closely enough.
you're creating itinerary series of locations , times trying model information indirectly smooshing trip , image objects in elaborate relationship.

instead, need entity models itinerary specifically.

itinerarystop{     name:string     arrivaltime:date     departuretime:date     location<<-->location.stops     image<<-->image.stop     trip<<-->trip.stop     previousstop<-->itenerarystop.nextstop     nextstop<-->intenerarystop.previousstop } 

now, everything falls place. stops in order particular trip, can either fetch on trip , and sort on arrivaltimes, can sort particular trip objects stops or if there no dates, can walk relationships.

in case, model more closely resembles real-world objects, events or conditions app deals with.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -