New Posts New Posts RSS Feed: MergeStrategy
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

MergeStrategy

 Post Reply Post Reply
Author
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Topic: MergeStrategy
    Posted: 07-Nov-2012 at 4:07pm
Understood, that is a good workaround - thanks for your help
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 07-Nov-2012 at 9:48am
Ah!, ok, now I understand.  We refer to these entities as "ghosts".  Entities that are removed elsewhere and still appear within the local cache.  Unfortunately, the breeze client does not yet detect "ghosts", which means that you will need to do this yourself for now.  The easiest way is to "detach" all of the children of any specific relation before requerying them.  If they exist they will be replaced, if not they will be gone. 

We hope to have "better" ghost semantics in a later version.
Back to Top
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Posted: 07-Nov-2012 at 3:50am
Hi there,

No problem - its a popular product!

You're correct above, except I'm not deleting then saving. The GuestTags are deleted externally, either through the database directly or from another site. When they are requeried they are still there, even though the json response generated doesn't contain them

I hope that clarifies things
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 06-Nov-2012 at 8:48am
Sorry, been buried here. 

Just to be clear,  within a single entityManager, you are querying a Guest and its collection of GuestTags. You then delete the GuestTags, (delete them, not detach them) and then save them.  But when you requery; the GuestTags come back.   If I got this right, it is a bug and we will fix it.  Please confirm that my scenario is correct.




Edited by jtraband - 06-Nov-2012 at 8:48am
Back to Top
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Posted: 06-Nov-2012 at 6:35am
Hi there, do you have any update on this?

It also comes into play with a few other entities I'm using which have child collections. When the database is updated the corresponding change is reflected in the json response, but not in the entitymanager (only for deletes, not additions)

Many thanks
Back to Top
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Posted: 04-Nov-2012 at 2:32pm
Yes, I have a Guest entity which has a collection of Tag entities. When I first get the guest with no tags the json comes back with an empty tag property. When I add a tag in the database and requery the guest, the json response contains 1 guest entity with a collection of tags as expected. When I then delete the tags from this guest and requery, the json response returns an empty tags property as expected but the entity manager doesn't remove the tags from the previous query, how would I remove these

Thanks
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 04-Nov-2012 at 10:56am
Not sure I understand, but to be clear "OverwriteChanges" forces new entities coming from the server to overwrite existing "matching" entities already on the client. So "OverwriteChanges" can never remove entities from the cache.

But maybe I'm misunderstanding your question, when you say "I remove the tag", do you mean that you are "deleting" the tag entity and resaving?
Back to Top
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2012 at 6:00am
Hi there,

Ok got it working after declaring above

But hasn't alleviated my initial problem, hence why I tried overwrite changes ...

 var query = new entityModel.EntityQuery().from("Guests")
                           .where("TimeStamp", ">", lastSyncTime).expand("GuestTags").using(mergeStrategy.OverwriteChanges);

        return manager.executeQuery(query);

Above I'm returning a list of guests with particular tags related to them back to the client. When I add a tag the tag is included in the json response and the model updated, when I remove the tag the json response updates so the property is blank, but the model doesn't remove the tag, it still displays unless I completely repopulate the manager.

I checked the _backingstore after a request and the 'expand' entities still seem to contain the original data, not relfecting the fact the tags were removed from the adjoining table...

Thanks 
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2012 at 1:17am
I was unable to recreate your issue, but it may just be that you are not qualifying QueryOptions and MergeStrategy - the full names for these are breeze.entityModel.QueryOptions and breeze.entityModel.MergeStrategy. 

We probably need to be clearer in our examples. :)

We tend to start our apps with some code like this in each module

    var entityModel = breeze.entityModel;

    var MetadataStore = entityModel.MetadataStore;
    var EntityManager = entityModel.EntityManager;
    var EntityQuery = entityModel.EntityQuery;
    ...
    var QueryOptions = entityModel.QueryOptions;
    var MergeStrategy = entityModel.MergeStrategy;
    ... etc.
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2012 at 12:42am
We are trying to repro your issue now but in the meantime you can also try applying the mergeStrategy directly to any query, i.e.

q = EntityQuery.
         .from("Customers")
         .where(....)
         .using(MergeStrategy.OverwriteChanges);

em.executeQuery(q).then(...).
Back to Top
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Posted: 02-Nov-2012 at 3:00pm
    var serviceName = 'api/demo';

    var queryOptions = new QueryOptions({
        mergeStrategy: MergeStrategy.OverwriteChanges,
        fetchStrategy: FetchStrategy.FromServer
    });

    var manager = new entityModel.EntityManager({ serviceName: serviceName, queryOptions: queryOptions });

QueryOptions doesn't seem to be recognised and if I do it inline, then MergeStrategy doesn't seem to be recognised

Thanks
Back to Top
Orizz View Drop Down
Newbie
Newbie


Joined: 15-Oct-2012
Posts: 16
Post Options Post Options   Quote Orizz Quote  Post ReplyReply Direct Link To This Post Posted: 02-Nov-2012 at 2:54pm
Hi there,

Think I'm being a bit stupid, but can't get this working or find any working examples of how to set this...

I need to be using MergeStrategy.OverwriteChanges, could you provide a working example on how to set this?

Many thanks


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down