...a longer string, the ActiveRecord validation will pass and then crash when making the SQL statement. The user sees an error box ("Something went wrong") instead of a validation error...
...you can use reset: user.posts.reset # discards cache, but does not load anything yet user.posts # SQL query happens to load new state # => [...] Note that reset returns the association/scope. Hence, the above...
...PostgreSQL dumps. This is no instruction for a backup strategy nor a guide for SQL dump performance optimization. Read before starting I will assume that all commands will be executed...
...and "USER", this will not trigger a validation error, but may fail with an SQL error due to duplicate index key. You can change Rails' behaviour, by saying
...should this not be an instance method? You can implement the search in either SQL or Ruby The form_for helper is not helpful for the search form above the...
...t want to allow null values in your ranges most of the time. Simple SQL queries There are a ton of operators that can be used with ranges. They all...
...some caching for you. There, it's perfectly fine as this is actually an SQL query (that you wouldn't want to do multiple times) and the association is actually...
...You Know, for Search" } Indexe Dokumente in Elastic leben in einem Index (analog zu SQL Table) Index erstellen: http PUT :9200/my_documents Index ansehen: http GET :9200/my_documents { "my_documents": { "aliases": { },
...Elasticsearch-Server auf einer Maschine Cluster ist zusammenschluss von Nodes (analog zu einer verteilten SQL Datenbank) Man redet effektiv immer mit dem Cluster Load-Balancing passiert intern automatisch
When storing floating-point numbers such as prices or totals in an SQL database, always use a DECIMAL column. Never use FLOAT or kittens will die. DECIMAL columns are parametrized...
...in the rails console and it will log the exact database interaction with related sql commands and its result. Before you know where to debug, you will often find yourself...
...and what tools Rails gives you to address it. Cross-Site Request Forgery (CSRF) SQL Injection Cross-Site Scripting (XSS) Content Security Policy Also A reasonable default Content Security Policy...
...You are submitting queries to fetch data in a given structure (like SELECT in SQL) or mutations to alter the database (similar to POST/PUT/DELETE in REST). You can control how...
...s Common Table Expressions (CTEs) can be used to extract sub-queries from bulky SQL statements into a temporary table to be referenced instead. This is most useful to avoid...
...example can also be achieved with Rails internals: Article.group(:brand).count. This translates to SQL, so it executes fast. However, grouping is restricted to columns (attributes). Using #count_by gives...
...string argument as the value for ‘column’. This string is passed directly to the SQL statement, making it possible to use all sorts of fun things to lock down the...
So regarding to the cited site Rails 5+ allows me to use an SQL statement in my index: t.index 'shop_id, lower(street), lower(house_number), lower(zip_code...
...many thousand keys). This means every association that you pivot around will trigger one SQL query...
When you want to filter records in a model where a string column roughly matches a given term, you can...
...column delegates to #pluck, which can be used for the same effect. Relation#to_sql # Rails 2 scope Post.scoped(:conditions => { :id => [1, 2] }).to_sql # => "SELECT `posts`.* FROM `posts` WHERE...
...posts.id` IN (1, 2)" ^ # Rails 3 relation Post.where(:id => [1, 2]).to_sql # => "SELECT `posts`.* FROM `posts` WHERE `posts.id` IN (1, 2)" Implementation note: Rails 3+ implements #to_sql.
...okay, but next automatic id will still be 101 Record.create! # will cause an SQL error 'duplicate key value violates unique constraint "records_pkey"' Workaround In tests, one workaround would be...
...With a Database Dump? Unfortunately not. Restoring from a logical database backup, i.e. an SQL dump, will not reproduce the error and is not suitable for testing changes, since importing...
...on any index oid # then it will drop the amcheck extension again list_index_sql=" SELECT c.oid FROM pg_index i JOIN pg_opclass op ON i.indclass[0] = op.oid
The change_column method for rails migrations support casting with a custom SQL statement. This allows us to change a column type and keep the former content as the new...
...you might load an outdated database structure. Since the schema.rb does not hold any SQL specific information, like charsets or collations, your test database may differ from your development database...
...without further information). To avoid this problem, your environment.rb needs to say: config.active_record.schema_format = :sql This will make a db/development_structure.sql appear which is then also read and loaded when you...
Using Scenic, you can bring the power of SQL views to your Rails application without having to switch your schema format to SQL. Scenic provides a convention for versioning views...
...that keeps your migration history consistent and reversible and avoids having to duplicate SQL strings across migrations. As an added bonus, you define the structure of your view in a...
...are consuming the most disk space. You can easily check this using the following SQL statement from the PostgreSQL wiki. SELECT nspname || '.' || relname AS "relation", pg_size_pretty(pg_total...