Rails “validates_uniqueness_of” Case Sensitivity

validates_uniqueness_of :name, :case_sensitive => false does the trick, but you should keep in mind that validates_uniqueness_of does not guarantee uniqueness if you have multiple servers/server processes (e.g. running Phusion Passenger, multiple Mongrels, etc) or a multi-threaded server. That’s because you might get this sequence of events (the order is important): Process A gets a request … Read more

What is the difference between an MVC Model object, a domain object and a DTO

Domain and model objects are essentially the same, and may contain business logic. Depending on implementation, domain and DTO objects may be equivalent if you remove business logic from the model into a service class. Often a key variant of the DTO is the View Model, which is used purely to transfer data between the … Read more

Eloquent ORM laravel 5 Get Array of ids

You could use lists() : test::where(‘id’ ,’>’ ,0)->lists(‘id’)->toArray(); NOTE : Better if you define your models in Studly Case format, e.g Test. You could also use get() : test::where(‘id’ ,’>’ ,0)->get(‘id’); UPDATE: (For versions >= 5.2 use ‘pluck()’ instead) The lists() method was deprecated in the new versions >= 5.2, now you could use pluck() … Read more

what is difference between a Model and an Entity

The definition of these terms is quite ambiguous. You will find different definitions at different places. Entity: An entity represents a single instance of your domain object saved into the database as a record. It has some attributes that we represent as columns in our tables. Model: A model typically represents a real world object … Read more

Removing a model in rails (reverse of “rails g model Title…”)

When you generate a model, it creates a database migration. If you run ‘destroy’ on that model, it will delete the migration file, but not the database table. So before run bundle exec rails db:rollback rails destroy model <model_name> For rails versions before 5.0 and higher use rake instead of rails bundle exec rake db:rollback … Read more

Difference between interfaces and classes in Typescript

2019: Update on Differences and Usages First, there is the obvious difference: syntax. This is a simple, but necessary to understand difference: Interface properties can end in commas or semi-colons, however class properties can only end in semi-colons. Now the interesting stuff. The sections about when to use and not to use may be subjective … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)