model

How to create dynamic, multiple partial views using repository pattern in MVC

这一生的挚爱 提交于 2020-01-13 02:09:32
问题 I am trying to have a general home page that depending on the parameter passed to the control, different content (modules) will be displayed. For example, a user may select Kentucky from the menu and the id for Kentucky is 1. The home controller gets the id (1) and determines the possible modules for that state (a simple db call.) Perhaps there is an announcements module and a contacts module for the state. An announcements module could have several items but it's only one module. There would

Using raw sql queries in Rails 3 application?

烈酒焚心 提交于 2020-01-12 16:10:36
问题 I am working on migrating a legacy database into my Rails application (3.2.3). The original database comes with quite a few long sql queries for reports. For now, what I would like to do it use the sql queries in the Rails application and then one by one (when time allows) swap the sql queries to 'proper' Rails queries. I have a clinical model and the controller has the following code: @clinical_income_by_year = Clinical.find_all_by_sql(SELECT date_format(c.transactiondate,'%Y') as Year, date

Using raw sql queries in Rails 3 application?

浪子不回头ぞ 提交于 2020-01-12 16:10:04
问题 I am working on migrating a legacy database into my Rails application (3.2.3). The original database comes with quite a few long sql queries for reports. For now, what I would like to do it use the sql queries in the Rails application and then one by one (when time allows) swap the sql queries to 'proper' Rails queries. I have a clinical model and the controller has the following code: @clinical_income_by_year = Clinical.find_all_by_sql(SELECT date_format(c.transactiondate,'%Y') as Year, date

MVC Mayhem; Sorting out Model responsibility and structure

孤街醉人 提交于 2020-01-12 07:14:26
问题 My understanding of MVC-type architectures over the last few weeks/months has advanced (I'd say) considerably, and I owe most of my thanks to fellow SO enthusiasts; so, thank you! I'm still challenged by something though, the Model . So far I've sorted out and created; A simple Request object, that consolidates request data (GET/POST/etc. params, HTTP headers, etc.) A simple Response object, that collects response data (HTML, JSON, HTTP headers, etc.) A fancy Router that resolves URIs against

Django DateTimeField auto_now_add not working

血红的双手。 提交于 2020-01-12 03:18:47
问题 In one of the model i have set one timestamp field as follows: created_datetime = models.DateTimeField(auto_now_add = True) While in shell i am able to create a obj and save it, however in my application it is raising a exception that created_datetime field cannot be null. Confused where things went wrong!! How to reslove it. 回答1: You can do something like this created_datetime = models.DateTimeField(auto_now_add=True, auto_now=False) 回答2: As far as I know, best practice for default datetimes

Blazor and Identity

非 Y 不嫁゛ 提交于 2020-01-11 13:53:29
问题 I have a project in .net core 3.0 with 3 parts : api, shared and a blazor app. I added few models in shared project and a user model : [Table("user")] public class User : IdentityUser<Guid> { [Required(ErrorMessage = "Firstname is required")] [StringLength(32, ErrorMessage = "Firstname must be 32 charaters maximum")] [Column("firstname")] public string Firstname { get; set; } [Required(ErrorMessage = "Lastname is required")] [StringLength(32, ErrorMessage = "Lastname must be 32 charaters

How can fit curve on this log data?

青春壹個敷衍的年華 提交于 2020-01-11 13:08:55
问题 I have a problem with a fit curve on this data: On x axes we have a data about wind intensity (m/s), on y axes we have log data (fish catch). I fitted a curve (nls model, Gaussian curve) only on data without logaritm, but when i tried on log data, R tell me: Error in nls(mean.w ~ k * exp(-1/2 * (x.wind - mu)^2/sigma^2), : singolar gradient The model is: mean.w ~ k * exp(-1/2 * (x.wind - mu)^2/sigma^2) , where k,mu and sigma are the parameters to estimate, and mean.w # is y axes (log fish

accessing devise current_user within model

狂风中的少年 提交于 2020-01-11 12:49:11
问题 hi i am trying to access current_user within a model for the purpose of creating an element on the fly with find_or_create_by. the following is the method within my model def opponent_name=(name) self.opponent = Opponent.find_or_create_by_name_and_team_id(name,current_user.team_id) if name.present? end but the error i am getting is NameError in EventsController#create undefined local variable or method `current_user' for #<Event:0x007fb575e92000> 回答1: current_user is not accessible from

Using Delegate With has_many In Rails?

跟風遠走 提交于 2020-01-11 05:13:25
问题 We've got 2 models & a join model: #app/models/message.rb Class Message < ActiveRecord::Base has_many :image_messages has_many :images, through: :image_messages end #app/models/image.rb Class Image < ActiveRecord::Base has_many :image_messages has_many :messages, through: :image_messages end #app/models/image_message.rb Class ImageMessage < ActiveRecord::Base belongs_to :image belongs_to :message end Extra Attributes We're looking to extract the extra attributes from the join model (

How to make all entities access:internal instead of public in EDMX?

♀尐吖头ヾ 提交于 2020-01-11 04:42:07
问题 I'd like my Entity Framework model to generate entities with internal access modifier, instead of public . I use the EF model in a library and I want only a single class (some controller) to be accessible from outside. Is there any simple way to make the EF model generation use internal modifer instead of public , including model regeneration on update? 回答1: It's very much like the anwer I got on a similar question. But in your case you want to customize the access modifier of the classes,