model

Laravel model Trailing Data when save the model

我只是一个虾纸丫 提交于 2020-01-11 00:05:33
问题 I have some code like this $editStuState = StuAtt::where('studentId' , '=' , $id)->first(); $editStuState -> leave +=1; $editStuState -> present = $editStuState -> present-1; $editStuState->update(); //OR $editStuState->save(); return 'this is good'; I can't save or Update my data, when I remove Update and Save related line it can print text. this is the dd($editStuState) data StuAtt {#382 ▼ #table: "stu_attendance" #connection: "mysql" #primaryKey: "id" #keyType: "int" +incrementing: true

Sqlalchemy mixins / and event listener

那年仲夏 提交于 2020-01-10 18:45:32
问题 I am attempting 2 new things at once, so assistance in both simplifying and clarifying is appreciated. from sqlalchemy.ext.declarative import declared_attr from sqlalchemy import Column, Float, event class TimeStampMixin(object): @declared_attr def __tablename__(cls): return cls.__name__.lower() created = Column(Float) modified = Column(Float) def __init__(self, created = None, modified = None): self.created = created self.modified = modified def create_time(mapper, connection, target):

Rails 4 multiple file attachments with Paperclip

陌路散爱 提交于 2020-01-10 15:42:42
问题 I'm aware that there are several posts on Stackoverflow and several tutorials about this subject. None of them however manage to solve my issue and most of them are outdated as well. I am trying to add multiple images to a project using the paperclip gem in Rails 4. When i try uploading it i do see the asset attached in the params. They do not seem to be added to the project_paramns though.. Hope someone can help me out here. This is my projects_controller class ProjectsController <

Rails 4 multiple file attachments with Paperclip

对着背影说爱祢 提交于 2020-01-10 15:41:11
问题 I'm aware that there are several posts on Stackoverflow and several tutorials about this subject. None of them however manage to solve my issue and most of them are outdated as well. I am trying to add multiple images to a project using the paperclip gem in Rails 4. When i try uploading it i do see the asset attached in the params. They do not seem to be added to the project_paramns though.. Hope someone can help me out here. This is my projects_controller class ProjectsController <

django model CharField: max_length does not work?

本秂侑毒 提交于 2020-01-09 11:06:07
问题 I'm trying to make a field with limited choices: Action_Types=( ('0','foo'), ('1','bar'), ) class Foo(models.Model): myAction=models.CharField(max_length=1,choices=Action_Types) def __unicode__(self): return '%d %s'%(self.pk,self.myAction) However, when I was trying to insert content violating the rules, it succeeded without any error or warning messages (with "manage.py shell"). It seems any text of any length can be put into this field. I'm using SQLite3 as the backend. Is it supposed to be

django model CharField: max_length does not work?

感情迁移 提交于 2020-01-09 11:02:05
问题 I'm trying to make a field with limited choices: Action_Types=( ('0','foo'), ('1','bar'), ) class Foo(models.Model): myAction=models.CharField(max_length=1,choices=Action_Types) def __unicode__(self): return '%d %s'%(self.pk,self.myAction) However, when I was trying to insert content violating the rules, it succeeded without any error or warning messages (with "manage.py shell"). It seems any text of any length can be put into this field. I'm using SQLite3 as the backend. Is it supposed to be

How to set a default attribute value for a Laravel / Eloquent model?

风格不统一 提交于 2020-01-09 02:17:09
问题 If I try declaring a property, like this: public $quantity = 9; ...it doesn't work, because it is not considered an "attribute", but merely a property of the model class. Not only this, but also I am blocking access to the actually real and existent "quantity" attribute. What should I do, then? 回答1: An update to this... @j-bruni submitted a proposal and Laravel 4.0.x is now supporting using the following: protected $attributes = array( 'subject' => 'A Post' ); Which will automatically set

Instance Variables in a Rails Model

丶灬走出姿态 提交于 2020-01-07 14:03:32
问题 I have this variable opinions I want to store as an instance variable in my model... am I right in assuming I will need to add a column for it or else be re-calculating it constantly? My other question is what is the syntax to store into a column variable instead of just a local one? Thanks for the help, code below: # == Schema Information # # Table name: simulations # # id :integer not null, primary key # x_size :integer # y_size :integer # verdict :string # arrangement :string # user_id

Consistently using associated model subclasses

谁说我不能喝 提交于 2020-01-07 09:47:14
问题 I have a situation where I have basic models that I want to add business logic to. For example, I might have something like this. class List < ApplicationRecord has_many :subscriptions has_many :subscribers, though: :subscriptions end class Subscriber < ApplicationRecord has_many :subscriptions has_many :lists, through: :subscriptions end class Subscription < ApplicationRecord belongs_to :list belongs_to :subscriber end Subscribing and unsubscribing is easy via the normal association methods.

Yii2: validation errors that are not attribute specific

可紊 提交于 2020-01-07 08:28:12
问题 How do I handle generic validation errors in a Yii2 ActiveRecord model that do not relate to a specific attribute ? For example I need to completely prohibit saving a model when a related record/modal has been set to inactive. I can of course just pick a more or less random attribute and assign the error message to it, but what if the front end form doesn't have that attribute and therefore doesn't show the error? Or even worse, if a scenario later disables validation of that attribute (by