I'm currently working on a project with Symfony 2 and MongoDB and I'm facing a problem while removing an Embed Document using is ID.
I'm working with Activities. An Activity embed a list of Comment and list of Vote.
A Comment can embed a list of Vote too.
To remove a Comment or a Vote from an Activity I do stuff like that :
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$activity = $dm->getRepository('SocialNetworkActivityBundle:Activity')
->findOneBy(array("votes.id" => $voteId));
$votes = $activity->getVotes();
$targetVote = null;
foreach ($votes as $vote)
if($vote->getId() == $voteId) {
$targetVote = $vote;
break;
}
$activity->removeVote($vote);
$dm->flush();
First of all, I know that the method I use isn't the best so I'm looking for an alternative.
Second of all, I can't use that method to remove a Vote embed in a Comment embed in an Activity, so I'm looking for a way to do that.
I don't find any solution in Doctrine documentation or on Stack (or other forum).
If you have some clues or advises for me I'll be really glad to read about :D
Related
I'm new at Apache Isis and I'm stuck.
I want to create my own submit form with editable parameters for search some entities and a grid with search results below.
Firstly, I created #DomainObject(nature=Nature.VIEW_MODEL) with search results collection, parameters for search and #Action for search.
After deeper research, I found out strict implementations for actions (For exapmle ActionParametersFormPanel). Can I use #Action and edit #DomainObject properties(my search parameters for action) without prompts?
Can I implement it by layout.xml?
Then I tried to change a component as described here: 6.2 Replacing page elements, but I was confused which ComponentType and IModel should I use, maybe ComponentType.PARAMETERS and ActionModel or implement my own IModel for my case.
Should I implement my own Wicket page for search and register it by PageClassList interface, as described here: 6.3 Custom pages
As I understood I need to replace page class for one of PageType, but which one should I change?
So, the question is how to implement such issues properly? Which way should I choose?
Thank you!
===================== UPDATE ===================
I've implemented HomePageViewModel in this way:
#DomainObject(
nature = Nature.VIEW_MODEL,
objectType = "homepage.HomePageViewModel"
)
#Setter #Getter
public class HomePageViewModel {
private String id;
private String type;
public TranslatableString title() {
return TranslatableString.tr("My custom search");
}
public List<SimpleObject> getObjects() {
return simpleObjectRepository.listAll();
}
#Action
public HomePageViewModel search(
#ParameterLayout(named = "Id")
String id,
#ParameterLayout(named = "Type")
String type
){
setId(id);
setType(type);
// finding objects by entered parameters is not implemented yet
return this;
}
#javax.inject.Inject
SimpleObjectRepository simpleObjectRepository;
}
And it works in this way:
I want to implement a built-in-ViewModel action with parameters without any dialog windows, smth like this:
1) Is it possible to create smth like ActionParametersFormPanel based on ComponentType.PARAMETERS and ActionModel and use this component as #Action in my ViewModel?
2) Or I should use, as you said, ComponentType.COLLECTION_CONTENTS? As I inderstand my search result grid and my search input panel will be like ONE my stub component?
Thank you.
We have a JIRA ticket in our JIRA to implement a filterable/searchable component, but it hasn't yet made it to the top of the list for implementation.
As an alternative, you could have a view model that provides the parameters you want to filter on as properties, with a table underneath. (I see you asked another question here on SO re properties on view models, so perhaps you are moving in that direction also... I've answered that question).
If you do want to have a stab at implementing that ticket, then the ComponentTYpe to use is COLLECTION_CONTENTS. If you take a look at the isisaddons, eg for excel or gmap3 then it might help get you started.
======= UPDATE TO ANSWER (based on update made to query) ==========
I have some good news for you. v1.15.0-SNAPSHOT, which should be released in the couple of weeks, has support for "inline prompts". You should find these give a user experience very similar to what you are after, with no further work needed on your part.
To try it out, check out the current trunk, and then load the simpleapp (in examples/application/simpleapp). You should see that editing properties and invoking actions uses the new inline prompt style.
HTH
Dan
I am using Xamarin Forms and their templates come with MvvMHelpers object to be used in the ViewModel as ObservableRangeCollections. I know ObservableCollections. If you try to do :
ObservableRangeCollection<Object> collection = new ObservableRangeCollection<Object>();
List<Object> objects = new List<Objects>();
collection.ReplaceRange(objects);
//error invalid type
Does anyone know how to use an ObservableRangeCollection? There is nothing on it in Google, Bing or StackOverflow.
Try the search you'll see Xamarin is promoting something so new that nobody knows what it is.
ObservableRangeCollection is a helper class by the Xamarin Evangelist James Montemagno.
The source is available in his github:
https://github.com/jamesmontemagno/mvvm-helpers
ObservableRangeCollection intends to help when adding/replacing Collections to a ObservableCollection.
In a "regular" ObservableCollection, for each new item added to the Collection, a OnCollectionChanged event would raise.
This is where ObservableRangeCollection gets in. It allows to replace/add elements to the Collection without firing an event for each element.
ObservableRangeCollection is subclassed from ObservableCollection.
So in your example, substitute your <T>, i.e:
ObservableRangeCollection<string> collection = new ObservableRangeCollection<string>();
List<string> objects = new List<string>();
collection.ReplaceRange(objects);
Consult the code here: https://github.com/jamesmontemagno/mvvm-helpers/blob/master/MvvmHelpers/ObservableRangeCollection.cs
This is not something that new. There's plenty of code using ObservableCollection.
What you are trying to achieve can be done like this:
List<Object> myList = new List<Objects>();
ObservableCollection<Object> myCollection = new ObservableCollection<Object>(myList);
Read more about ObservableCollection.
Check out my answer here, which is an enhanced version of ObservableRangeCollection optimized for less event raising and reuse of items in UI.
I am using Tastypie, Django for my project.
To Update a many to many field I have used save_m2m hook.
def save_m2m(self, bundle):
for field_name, field_object in self.fields.items():
if not getattr(field_object, 'is_m2m', False):
continue
if not field_object.attribute:
continue
if field_object.readonly:
continue
related_mngr = getattr(bundle.obj, field_object.attribute)
related_objs = []
print bundle.data[field_name]
for related_bundle in bundle.data[field_name]:
try:
stock = Stock.objects.get(nse_symbol = related_bundle.obj.nse_symbol)
print stock.__dict__
except Stock.DoesNotExist as e:
dataa = {"error_message": e}
raise ImmediateHttpResponse(response=HttpBadRequest(content=json.dumps(dataa), content_type="application/json; charset=UTF-8"))
related_objs.append(stock)
related_mngr.add(*related_objs)
Now I want to remove elements from the same many to many field.
How should I achieve this. Do I have to send a patch request or delete request and how to handle this.
I am begineer in tastypie. I googled it some time and I couldn't find a proper way. Please guide me how to complete this.
Thanks.
I've thought a lot about handing m2m relationships, since most of our app depends on m2m links.
I've settled for the approach of an update method. Pass in the all the references of the relationships you want changed (add and remove), then update the db accordingly. We only pass in the changed values, since if you have a paginated list, you only want to update the items the user has identified. Generally I use a custom hook for this defined in override_urls.
I used to have a separate add and remove method, which worked well until we changed the gui and allowed users simply to change checkboxes. In that approach having an update method was much more useful. You'll have to decide on which method suits your application the best.
i have this parsed object
$xmlObj = new SimpleXMLElement($XMLToParse, LIBXML_DOTTED_VERSION, FALSE, "http://SOME/schema/universal_v17_0");
that has the stucture like this inside it
<universal:UniversalR LocatorCode="somecode" Version="2" Status="Active">
<common_v17_0:Book Key="some" TravelerType="some">
so i can access the first element(its attributes) like this $VariableX=$xmlObj->UniversalR->attributes();//then $VariableX["Status"];
but when i want access his child i cant $tm=$xmlObj->UniversalR->Book->attributes();
it doesnt want to enter probably because of the different namespace...can any one help me . THX
I found something here http://blog.sherifmansour.com/?p=302
foreach ($xmlObj->UniversalRecord as $entry){
$namespaces = $entry->getNameSpaces(true);
$cmm = $entry->->children($namespaces['common_v17_0']);
$aa=$cmm->Book->attributes();
echo $aa["TravelerType"]."ddddd";
}
That should do it :)
$tm=$xmlObj->UniversalRecord->Book->attributes(); is this typo (UniversalRecord instead of UniversalR) only present in this post or is it also present in your code?
(I'd have liked to post this as a comment.. but it looks like i'm not allowed to, or am too stupid to find the button. :/)
I'm trying to add a search field to my web site (ASP.NET MVC 2) and was told it'd be a good idea to use Nhibernate.Search, seeing that I was already using Nhibernate in the rest of the project.
Anyway, I followed a coulpe tutorials, namely this one, and some questions and answeres on this site, but in the end, it does not build an index, and searches come empty.
I know this question might be a bit vague, but it seems strange that nothing works even after I've done everything I was told.
Well, almost everything. At some point, in one of the tutorials, it tells me to type:
using (IFullTextSession s = Search.CreateFullTextSession(sf.OpenSession(new SearchInterceptor()))) {
QueryParser qp = new QueryParser("id", new StopAnalyzer());
IQuery NHQuery = s.CreateFullTextQuery(qp.Parse("Summary:series"), typeof(Book));
IList result = NHQuery.List();
Debug.Assert(result.Count == 2);
}
wich does not work because SearchInterceptor does not exist anywhere...
Am I missing something here?
Is there a way to better write the search queries?
In which part of my application does it build the index?
Thanks in advance.
I've tried something like:
public bool LuceneIndexAllVideos()
{
var s = NHibernate.Search.Search.CreateFullTextSession(Session);
foreach (Video video in Videos)
{
s.Index(video);
}
return true;
}
But is slow, but it seems to work nice...
See:
https://stackoverflow.com/questions/6989125/lucene-net-nhibernate-updating-lucene-index-from-existing-data