Search Results

Search found 13429 results on 538 pages for 'model reject'.

Page 88/538 | < Previous Page | 84 85 86 87 88 89 90 91 92 93 94 95  | Next Page >

  • How to programmatically bind to a Core Data model?

    - by Dave Gallagher
    Hello. I have a Core Data model, and was wondering if you know how to create a binding to an Entity, programmatically? Normally you use bind:toObject:withKeyPath:options: to create a binding. But I'm having a little difficulty getting this to work with Core Data, and couldn't find anything in Apple's docs regarding doing this programmatically. The Core Data model is simple: An Entity called Book An Attribute of Book called author (NSString) I have an object called BookController. It looks like so: @interface BookController : NSObject { NSString *anAuthor; } @property (nonatomic, retain) NSString *anAuthor; // @synthesize anAuthor; inside @implementation I'd like to bind anAuthor inside BookController, to author inside a Book entity. This is how I'm attempting to wrongly do it (it partially works): // A custom class I made, providing an interface to the Core Data database CoreData *db = [[CoreData alloc] init]; // Creating a Book entity, saving it [db addMocObject:@"Book"]; [db saveMoc]; // Fetching the Book entity we just created NSArray *books = [db fetchObjectsForEntity:@"Book" withPredicate:nil withSortDescriptors:nil]; NSManagedObject *book = [books objectAtIndex:0]; // Creating the binding BookController *bookController = [[BookController alloc] init]; [bookController bind:@"anAuthor" toObject:book withKeyPath:@"author" options:nil]; // Manipulating the binding [bookController setAnAuthor:@"Bill Gates"]; Now, when updating from the perspective of bookController, things don't work quite right: // Testing the binding from the bookController's perspective [bookController setAnAuthor:@"Bill Gates"]; // Prints: "bookController's anAuthor: Bill Gates" NSLog(@"bookController's anAuthor: %@", [bookController anAuthor]); // OK! // ERROR HERE - Prints: "bookController's anAuthor: (null)" NSLog(@"Book's author: %@", [book valueForKey:@"author"]); // DOES NOT WORK! :( When updating from the perspective of the Book entity, things work fine: // ------------------------------ // Testing the binding from the Book's (Entity) perspective (this works perfect) [book setValue:@"Steve Jobs" forKey:@"author"]; // Prints: "bookController's anAuthor: Steve Jobs" NSLog(@"bookController's anAuthor: %@", [bookController anAuthor]); // OK! // Prints: "bookController's anAuthor: Steve Jobs" NSLog(@"Book's author: %@", [book valueForKey:@"author"]); // OK! It appears that the binding is partially working. I can update it on the side of the Model and it propagates up to the Controller via KVO, but if I update it on the side of the Controller, it doesn't trickle down to the Model via KVC. Any idea on what I'm doing wrong? Thanks so much for looking! :)

    Read the article

  • How can I add dynamic field in the model in django ?

    - by Wu Jie
    Hello, I'm using django to create a application download site. I try to write a model, that the admin can add the different download content dynamically in the admin page. For example I have a software named foobar, it have 3 different version: 1.1, 1.2, 1.3. I would like the user can admin the model by using an add button to add the download link with a download version. But I don't know how to do this in django.

    Read the article

  • In MVVM should the ViewModel or Model implement INotifyPropertyChanged?

    - by Edward Tanguay
    Most MVVM examples I have worked through have had the Model implement INotifyPropertyChanged, but in Josh Smith's CommandSink example the ViewModel implements INotifyPropertyChanged. I'm still cognitively putting together the MVVM concepts, so I don't know if: you have to put the INotifyPropertyChanged in the ViewModel to get CommandSink to work this is just an aberration of the norm and it doesn't really matter you should always have the Model implement INotifyPropertyChanged and this is just a mistake which would be corrected if this were developed from a code example to an application What have been others' experiences on MVVM projects you have worked on?

    Read the article

  • Ruby on Rails: Find records based on a method in the model?

    - by sjsc
    I'm looking to use named_scope to find records based on a method in the model. Right now I have in my Order.rb model: def self.paid collect { |order| order if order.paid? } end # the method def paid order.payments.total >= order.total_price end That works, but I can't chain it if I have a shipped named_scope: named_scope :shipped, :conditions => "shipped is true" And I wanted to do: Order.paid.shipped which doesn't work. Any ideas?

    Read the article

  • Microsoft Solver Foundation constraint

    - by emaster70
    Hello, I'm trying to use Microsoft Solver Foundation 2 to solve a fairly complicated situation, however I'm stuck with an UnsupportedModelException even when I dumb down the model as much as possible. Does anyone have an idea of what I'm doing wrong? Following is the least example required to reproduce the problematic behavior. var ctx = SolverContext.GetContext(); var model = ctx.CreateModel(); var someConstant = 1337.0; var decisionA = new Decision(Domain.Real, "decisionA"); var decisionB = new Decision(Domain.Real, "decisionB"); var decisionC = new Decision(Domain.Real, "decisionC"); model.AddConstraint("ca", decisionA <= someConstant); model.AddConstraint("cb", decisionB <= someConstant); model.AddConstraint("cc", decisionC <= someConstant); model.AddConstraint("mainConstraint", Model.Equal(Model.Sum(decisionA, decisionB, decisionC), someConstant)) model.AddGoal("myComplicatedGoal", GoalKind.Minimize, decisionC); var solution = ctx.Solve(); solution.GetReport().WriteTo(Console.Out); Console.ReadKey(); Please consider that my actual model should include, once complete, a few constraints in the form of a*a+b*a <= someValue, so if what I'm willing to do ultimately isn't supported, please let me know in advance. If that's the case I'd also appreciate a suggestion of some other solver with a .NET friendly interface that I could use (only well-known commercial packages, please). Thanks in advance

    Read the article

  • Is it possible to dynamically discover tables in an Entity Framework model ?

    - by Scott Davies
    Hi, I have co-workers working on an Entity Framework model that changes structure (entities), over time as software development progresses. I've written some utilities that interact with the tables within the model, but I'd like to have the code dynamically discover the tables. Is there a way I can do this ? Perhaps with ADO.NET to get the table names and then store them in a collection ? Thanks, Scott

    Read the article

  • Jena Effects of Different Entailment Regimes

    - by blueomega
    I am trying sparql and the use of entailment. As a example i used http://www.w3.org/TR/2010/WD-sparql11-entailment-20100126/#t112 i try to put them in jena. OntClass book1= model.createClass(NS+"book1"); OntClass book2=model.createClass(NS+"book2"); OntClass book3=model.createClass(NS+"book3"); OntClass publication=model.createClass(NS+"publication"); OntClass article=model.createClass(NS+"article"); OntClass mit=model.createClass(NS+"MIT"); ObjectProperty a = model.createObjectProperty(NS+"a"); ObjectProperty publishes = model.createObjectProperty(NS+"publishes"); book1.addProperty(a, publication); book2.addProperty(a, article); publication.addSubClass(article); publishes.addRange(publication); mit.addProperty(publishes, book3); where model is type OntModel. and i used the query similar to the problem "PREFIX table: "I have correct namespace here"+ "SELECT *"+ "WHERE"+ "{"+ " ?x ?y table:publication ."+ "}"; The model was created like this. Hope OntModelSpec is ok. OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF, null); i get as results from query x y | http://www.example.com/ontologies/sample.owl#publishes | rdfs:range | | http://www.example.com/ontologies/sample.owl#article | rdfs:subClassOf | | http://www.example.com/ontologies/sample.owl#book1 | http://www.example.com/ontologies/sample.owl#a | | http://www.example.com/ontologies/sample.owl#publication | rdfs:subClassOf | | http://www.example.com/ontologies/sample.owl#book3 | rdf:type | Can anyone give me a example, with and without entailment, so a cant try code, can get the results right.

    Read the article

  • CakePHP: Can I ignore a field when reading the Model from the DB?

    - by Daniel Magliola
    In one of my models, I have a "LONGTEXT" field that has a big dump of a bunch of stuff that I never care to read, and it slows things down, since I'm moving much more data between the DB and the web app. Is there a way to specify in the model that I want CakePHP to simply ignore that field, and never read it or do anything with it? I really want to avoid the hassle of creating a separate table and a separate model, only for this field. Thanks! Daniel

    Read the article

  • Django admin breaking with non-default primary_key for model with a m2m relationship ?

    - by Gj
    I have a simple Post model with a m2m field to a Tag model. The Tag had for some reason to use a non default primary key. Inside the admin page for a Post, the labels for the multiple selection field for Tags appear, but not the input field itself. I also tried using the filter_horizontal for the tags, but still only the labels appear without the actual field. Any ideas why it breaks and/or workarounds? Thanks!

    Read the article

  • Crashes in Core Data's Inferred Mapping Model Creation (Lightweight Migration). Threading Issue?

    - by enchilada
    I'm getting random crashes when creating an inferred mapping model (with Core Data's lightweight migration) within my application. By the way, I have to do it programmatically in my application while it is running. This is how I create this model (after I have made proper currentModel and newModel objects, of course): NSMappingModel *mappingModel = [NSMappingModel inferredMappingModelForSourceModel:currentModel destinationModel:newModel error:&error]; The problem is this: This method is crashing randomly. When it works, it works just fine without issues. But when it crashes, it crashes my application (instead of returning nil to signify that the method failed, as it should). By randomly, I mean that sometimes it happens and sometimes not. It is unpredictable. Now, here is the deal: I'm running this method in another thread. More precisely, it is located inside a block that is passed via GCD to run on the global main queue. I need to do this for my UI to appear crisp to the user, i.e. so that I can display a progress indicator while the work is underway. The strange thing seems to be that if I remove the GCD stuff and just let it run on the main thread, it seems to be working fine and never crashing. Thus, could it be because I'm running this on a different thread that this is crashing? I somehow find that weird because I don't believe I'm breaking any Core Data rules regarding multi-threading. In particular, I'm not passing any managed objects around, and whenever I need access to the MOC, I create a new MOC, i.e. I'm not relying on any MOC (or for that matter: anything) that has been created earlier on the main thread. Besides the little MOC stuff that occurs, occurs after the mapping model creation method, i.e. after the point at which the app crashes, so it can't possibly be a cause of the crashes under consideration here. All I'm doing is taking two MOMs and asking for a mapping model between them. That can't be wrong even under threading, now can it? Any ideas on what could be going on?

    Read the article

  • Qt – How to add calculated column in QsqlRelationalTableModel ?

    - by user289175
    I have an table view showed part description, quantity, price And I have a Model/View using this code model = new QSqlRelationalTableModel(this); model->setTable("parts"); model->setRelation(3,QSqlRelation("part_tbl","part_id","part_desc")); model->select(); ui->tableView->setModel(model); I need to add a new column that shows quantity * price in the table view. It's important to know I'm using QsqlRelationalTableModel Help is appreciated, Thanks in advance

    Read the article

  • Is it safe to put reference to current user in User model in Rails?

    - by Art Shayderov
    You know, I think I have to check current user in the model callbacks (like before_update). Rather than rely solely on adding where ('something.user_id = ?', 'current_user.id') in the controllers. I need something like Thread.CurrentPrincipal in .NET Is it safe to put reference to current user in User model? I'm sorry I don't really understand how it works under the hood yet. Or how you do it The Rails way? Sorry if this a silly question.

    Read the article

  • Bad practice to have models made up of other models?

    - by mattruma
    I have a situation where I have Model A that has a variety of properties. I have discovered that some of the properties are similar across other models. My thought was I could create Model B and Model C and have Model A be a composite with a Model B property and a Model C property. Just trying to determine if this is the best way to handle this situation.

    Read the article

  • Spring 3 MVC - Form Failure Causes Exception When Reloading JSP

    - by jboyd
    Using Spring 3 MVC, please bear with the long code example, it's quite simple, but I want to make sure all relevant information is posted. Basically here is the use case: There is a registration page, a user can login, OR fill out a registration form. The login form is a simple HTML form, the registration form is a more complicated, Spring bound form that uses a RegistrationFormData bean. Here is the relevant code: UserController.java ... @RequestMapping(value = "/login", method = RequestMethod.GET) public String login(Model model) { model.addAttribute("registrationInfo", new ProfileAdminFormData()); return "login"; } ... @RequestMapping(value = "/login.do", method = RequestMethod.POST) public String doLogin( @RequestParam(value = "userName") String userName, @RequestParam(value = "password") String password, Model model) { logger.info("login.do : userName=" + userName + ", password=" + password); try { getUser().login(userName, password); } catch (UserNotFoundException ex) { logger.error(ex); model.addAttribute("loginError", ex.getWebViewableErrorMessage()); return "login"; } return "redirect:/"; } ... @RequestMapping(value = "/register.do") public String register( @ModelAttribute(value = "registrationInfo") ProfileAdminFormData profileAdminFormData, BindingResult result, Model model) { //todo: redirect if (new RegistrationValidator(profileAdminFormData, result).validate()) { try { User().register(profileAdminFormData); return "index"; } catch (UserException ex) { logger.error(ex); model.addAttribute("registrationErrorMessage", ex.getWebViewableErrorMessage()); return "login"; } } return "login"; } and the JSP: ... <form:form commandName="registrationInfo" action="register.do"> ... So the problem here is that when login fails I get an exception because there is no bean "registrationInfo" in the model attributes. What I need is that regardless of the path through this controller that the "registrationInfo" bean is not null, that way if login fails, as opposed to registration, that bean is still in the model. As you can see I create the registrationInfo object explicitly in my controller in the method bound to "/login", which is what I thought was going to be kind of a setup method" Something doesn't feel right about the "/login" method which sets up the page, but I needed to that in order to get the page to render at all without throwing an exception because there is no "registrationInfo" model attribute, as needed by the form in the JSP

    Read the article

  • If I create a transient property in the model, isn't this managed by core data then?

    - by mystify
    Just to grok this: If I had a transient property, lets say averagePrice, and I mark that as "transient" in the data modeler: This will not be persistet, and no column will be created in SQLite for that? And: If I make my own NSManagedObject subclass with an averagePrice property, does it make any sense to model that property in the xcdatamodel file? Would it make a difference if I would simply create a property in my subclass and not model that in the entity? (I think: yes, it doesn't matter at all ... but not sure)

    Read the article

  • JPA: what is the proper pattern for iterating over large result sets?

    - by Caffeine Coma
    Let's say I have a table with millions of rows. Using JPA, what's the proper way to iterate over a query against that table, such that I don't have all an in-memory List with millions of objects? I suspect that the following will blow up if the table is large: List<Model> models = entityManager().createQuery("from Model m", Model.class).getResultList(); for (Model model : models) { // do something with model } Is pagination (looping and manually updating setFirstResult()/setMaxResult()) really the best solution?

    Read the article

  • ASP.NET MVC Unit Testing Controllers - Repositories

    - by Brian McCord
    This is more of an opinion seeking question, so there may not be a "right" answer, but I would welcome arguments as to why your answer is the "right" one. Given an MVC application that is using Entity Framework for the persistence engine, a repository layer, a service layer that basically defers to the repository, and a delete method on a controller that looks like this: public ActionResult Delete(State model) { try { if( model == null ) { return View( model ); } _stateService.Delete( model ); return RedirectToAction("Index"); } catch { return View( model ); } } I am looking for the proper way to Unit Test this. Currently, I have a fake repository that gets used in the service, and my unit test looks like this: [TestMethod] public void Delete_Post_Passes_With_State_4() { //Arrange var stateService = GetService(); var stateController = new StateController( stateService ); ViewResult result = stateController.Delete( 4 ) as ViewResult; var model = (State)result.ViewData.Model; //Act RedirectToRouteResult redirectResult = stateController.Delete( model ) as RedirectToRouteResult; stateController = new StateController( stateService ); var newresult = stateController.Delete( 4 ) as ViewResult; var newmodel = (State)newresult.ViewData.Model; //Assert Assert.AreEqual( redirectResult.RouteValues["action"], "Index" ); Assert.IsNull( newmodel ); } Is this overkill? Do I need to check to see if the record actually got deleted (as I already have Service and Repository tests that verify this)? Should I even use a fake repository here or would it make more sense just to mock the whole thing? The examples I'm looking at used this model of doing things, and I just copied it, but I'm really open to doing things in a "best practices" way. Thanks.

    Read the article

  • Passing ViewModel for backbone.js from MVC3 Server-Side

    - by Roman
    In ASP.NET MVC there is Model, View and Controller. MODEL represents entities which are stored in database and essentially is all the data used in a application (for example, generated by EntityFramework, "DB First" approach). Not all data from model you want to show in the view (for example, hashs of passwords). So you create VIEW MODEL, each for every strongly-typed-razor-view you have in application. Like this: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MyProject.ViewModels.SomeController.SomeAction { public class ViewModel { public ViewModel() { Entities1 = new List<ViewEntity1>(); Entities2 = new List<ViewEntity2>(); } public List<ViewEntity1> Entities1 { get; set; } public List<ViewEntity2> Entities2 { get; set; } } public class ViewEntity1 { //some properties from original DB-entity you want to show } public class ViewEntity2 { } } When you create complex client-side interfaces (I do), you use some pattern for javascript on client, MVC or MVVM (I know only these). So, with MVC on client you have another model (Backbone.Model for example), which is third model in application. It is a bit much. Why don`t we use the same ViewModel model on a client (in backbone.js or another framework)? Is there a way to transfer CS-coded model to JS-coded? Like in MVVM pattern, with knockout.js, when you can do like this: in SomeAction.cshtml: <div style="display: none;" id="view_model">@Json.Encode(Model)</div> after that in Javascript-code var ViewModel = ko.mapping.fromJSON($("#view_model").get(0).innerHTML); now you can extend your ViewModel with some actions, event handlers, etc: ko.utils.extend(ViewModel, { some_function: function () { //some code } }); So, we are not building the same view model on the client again, we are transferring existing view model from server. At least, data. But knockout.js is not suitable for me, you can`t build complex UI with it, it is just data-binding. I need something more structural, like backbone.js. The only way to build ViewModel for backbone.js I can see now is re-writing same ViewModel in JS from server with hands. Is there any ways to transfer it from server? To reuse the same viewmodel on server view and client view?

    Read the article

  • Asp.NET MVC View with different objects

    - by user195910
    If i have a controller action "Create" that returns a view with the following as the Model type: public class PaymentModel { public Model.SummaryInformation SummaryInformation; public Model.CardDetail CardDetail; } If there is a button on this view that POST's to an action "New" and I want that action to recieve a different object e.g. public class PaymentNewModel { public Model.CardDetail CardDetail; } Is this possible? I do not want to use the same Model when the view is rendered to the Model that is POSTed

    Read the article

< Previous Page | 84 85 86 87 88 89 90 91 92 93 94 95  | Next Page >