Commit Graph

166 Commits

Author SHA1 Message Date
beerlington
3da275c439 Accept belongs_to assoc. keys in ActiveRecord queries
Allows you to specify the model association key in a belongs_to
relationship instead of the foreign key.

The following queries are now equivalent:

Post.where(:author_id => Author.first)
Post.where(:author => Author.first)

PriceEstimate.where(:estimate_of_type => 'Treasure', :estimate_of_id => treasure)
PriceEstimate.where(:estimate_of => treasure)
2012-09-11 14:11:51 -04:00
Yves Senn
319482d8fe postgres, map scaled intervals to string datatype (#7518) 2012-09-06 18:01:34 +02:00
Dickson S. Guedes
3b516b5beb ActiveRecord support to PostgreSQL 9.2 JSON type
This implements the support to encode/decode JSON
data to/from database and creating columns of type
JSON using a native type [1] supported by PostgreSQL
from version 9.2.

[1] http://www.postgresql.org/docs/9.2/static/datatype-json.html
2012-09-05 22:39:43 -03:00
Ian Lesperance
c7d752fe2f Fix pluck when columns/tables are reserved words. 2012-09-05 18:00:07 -04:00
Yves Senn
9f494a9a34 test cleanup, remove ruby_type because it's no longer needed
All tests with a custom inheritance_column use the `Vegtable` model.
The field ruby_type on the Company models is no longer needed
2012-09-03 20:38:14 +02:00
Yves Senn
77ca2815f5 rewrite inheritance tests with a custom inheritance_column
previously the tests with and without a custom `inheritance_column`
used the same models. Since the model then has both fields this can lead
to false positives.
2012-09-03 20:30:43 +02:00
Yves Senn
20574956d1 set the configured #inheritance_column on #become (#7503)
I had to create a new table because I needed an STI table,
which does not have both a "type" and a "custom_type"

the test fails with:
  1) Error:
test_alt_becomes_works_with_sti(InheritanceTest):
NoMethodError: undefined method `type=' for #<Cabbage id: 1, name: "my cucumber", custom_type: "Cucumber">
    /Users/username/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:432:in `method_missing'
    /Users/username/Projects/rails/activerecord/lib/active_record/attribute_methods.rb💯in `method_missing'
    /Users/username/Projects/rails/activerecord/lib/active_record/persistence.rb:165:in `becomes'
    test/cases/inheritance_test.rb:134:in `test_becomes_works_with_sti'
    test/cases/inheritance_test.rb:140:in `test_alt_becomes_works_with_sti'
2012-09-03 16:08:16 +02:00
Dave Desrochers
ff0d9b93b9 reset_counters() was crashing when there were multiple belongs_to associations with the same foreign key.
This closes #5200.
2012-08-21 14:10:11 -03:00
Yasuo Honda
708b5c0d3a Modity the :json_data_empty attribute from :null => false to :null => true
to address ORA-01400 errors with Oracle enhanced adapter.

The original commit 3c0bf043 requires :json_data_empty attribute
has empty string OR null, then setting `:default => ""` is enough.
2012-07-28 04:43:04 +09:00
Yasuo Honda
dab8ca53be Modify the preference attribute from :null => false to :null => true
to address ORA-01400 errors with Oracle enhanced adapter.

Issue #4856 had been fixed and tested with
the attribute `:null => false, :default => ""`.
Now `:null => false` attribute is not necessary to test this issue.
2012-07-27 10:31:59 +09:00
Yasuo Honda
05895c6c86 Use string datatype for the setting attribute
to make store works all database adapters.
2012-07-26 02:19:23 +09:00
Yasuo Honda
0da49506f1 This pull requests addresses ORA-01400 errors and also supports #6115 issue tested.
Issue #6115 has been fixed and tested with
the attribute `:null => false, :default => ""`
However `:null => false` attribute is not necessary to test this issue,
which causes many ORA-01400 errors with Oracle enhanced adapter.
2012-07-25 03:51:23 +09:00
Yamada Masaki
f49800071f fix: limit of enum columns of mysql 2012-06-28 03:15:43 +09:00
Piotr Sarnacki
ceb68d1874 Revert "Merge pull request #6344"
This commit needs to be reverted because it introduces difficulties when
using sqlite3 in development and other databases in production. This
happens because when you create time column in sqlite3, it's dumped as
datetime in schema.rb file.

This reverts commit 57d534ee9e441d078fcc161c0c78ebaa5aacd736, reversing
changes made to 20f049fb50daee0c5e5a69b55b529af5737e8e3f.

Conflicts:

	activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
2012-06-25 02:27:26 +02:00
Andrew White
46492949b8 Improve the derivation of HABTM assocation join table names
Improve the derivation of HABTM join table name to take account of nesting.
It now takes the table names of the two models, sorts them lexically and
then joins them, stripping any common prefix from the second table name.

Some examples:

  Top level models
  (Category <=> Product)
  Old: categories_products
  New: categories_products

  Top level models with a global table_name_prefix
  (Category <=> Product)
  Old: site_categories_products
  New: site_categories_products

  Nested models in a module without a table_name_prefix method
  (Admin::Category <=> Admin::Product)
  Old: categories_products
  New: categories_products

  Nested models in a module with a table_name_prefix method
  (Admin::Category <=> Admin::Product)
  Old: categories_products
  New: admin_categories_products

  Nested models in a parent model
  (Catalog::Category <=> Catalog::Product)
  Old: categories_products
  New: catalog_categories_products

  Nested models in different parent models
  (Catalog::Category <=> Content::Page)
  Old: categories_pages
  New: catalog_categories_content_pages

Also as part of this commit the validity checks for HABTM assocations have
been moved to ActiveRecord::Reflection One side effect of this is to move when
the exceptions are raised from the point of declaration to when the association
is built. This is consistant with other association validity checks.
2012-06-22 06:27:11 +01:00
Konstantin Shabanov
12e9a75f22 Add uuid type support to PostgreSQL adapter 2012-06-14 17:44:51 +04:00
Aaron Patterson
8067857bdf Merge pull request #6238 from pwnall/pgsql_bytea_limit
Postgresql doesn't accept limits on binary (bytea) columns.
2012-05-17 10:56:39 -07:00
Erich Menge
d9fc180fb4 SQLite3 doesn't actually support the 'time' type. 2012-05-15 22:05:00 -05:00
Rafael Mendonça França
1839ecd228 MySQL doesn't allow default values for blobs. 2012-05-13 20:12:00 -03:00
Rafael Mendonça França
f443e119cd Merge pull request #5807 from Antiarchitect/store-improvement
Custom coders support for ActiveRecord::Store.
2012-05-13 15:02:31 -07:00
angelo giovanni capilleri
47570d4f1f mispelling errors in render_text_test.rb and sqlite_specific_schema 2012-05-12 13:19:28 +02:00
Victor Costan
99ed99bb51 Postgresql doesn't accept limits on binary (bytea) columns. 2012-05-09 23:38:24 -04:00
Andrey Voronkov
3c0bf0435c Custom coders support for ActiveRecord::Store. JSON, YAML, Marshal can be used out of the box. 2012-05-09 19:20:14 +04:00
Michael Pearson
a9721d8941 Modify test schema.rb to use a VARCHAR rather than a TEXT when a default is required to keep MySQL happy. 2012-05-05 17:17:04 +10:00
Piotr Sarnacki
c5176023a0 Duplicate column_defaults properly (closes #6115) 2012-05-04 23:00:41 -07:00
Prem Sichanugrist
5156110476 Create plpgsql language if not available
This should fix the problem in Travis CI server.
(http://travis-ci.org/#!/rails/rails/jobs/1194988)
2012-04-27 22:58:04 -04:00
Doug Cole
f09bb33bb5 add use_returning as a postgresql connection config 2012-03-31 17:14:28 -07:00
Jon Leighton
bd40e5c9e4 whitespace ✂️ 2012-03-30 14:36:33 +01:00
Jon Leighton
2eb111815d Merge pull request #5334 from courtland/master
Fix deleting from a HABTM join table upon destroying an object of a model with optimistic locking enabled.
2012-03-30 06:08:05 -07:00
Jonathan Mukai & Peter Jaros
135d704a55 Nested attribute setters can be overridden.
Overriding implementation can call super.
2012-03-28 19:08:31 -04:00
Aaron Patterson
e96d04a2e4 attributes are cached by string keys, so to_s to support symbols. fixes #5549 2012-03-27 11:27:51 -07:00
Nick Rogers
2931f413a5 Tests for removing a HABTM association when optimistic locking is enabled. 2012-03-07 23:56:23 -05:00
kennyj
fe7cacb510 Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931. 2012-02-26 00:35:58 +09:00
Aaron Patterson
04c0aea47a Merge pull request #5000 from flavorpill/master-with-multidb-association-fix
Fix associations with per-class/multiple database connections
2012-02-13 09:11:33 -08:00
Rick Martinez
30b6d4f7f1 added test for #3732 2012-02-10 17:35:22 -05:00
Aaron Patterson
f7b915b507 Merge branch 'joelhoffman-postgres_schema_builder' into instance_reader
* joelhoffman-postgres_schema_builder:
  Also support writing the hstore back to the database
  Hstore values are all strings
  string_to_hstore / hstore_to_string, serializing
  don't test schema where hstore not installed
  schema dumper tests for hstore
  Additional hstore tests, supporting null values, better compliance with postgres docs
  add hstore to postgres native types and defaults

Conflicts:
	activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
2012-02-10 10:55:34 -08:00
Joel
2967aecdaf don't test schema where hstore not installed 2012-02-08 22:28:51 -08:00
Joel
102ef98d32 schema dumper tests for hstore 2012-02-08 22:28:51 -08:00
Marcelo Silveira
7ef22fce7c Made schema dumper recognize partial indices' where statements 2012-02-09 03:28:11 -02:00
Jeremy Walker
58d10e2012 Allow store to be a not null column. 2012-02-02 18:57:15 +00:00
Aaron Patterson
33fda1ca56 Merge pull request #4696 from rafaelfranca/issue-4653
Remove extra attributes from HABTM join tables in AR tests
2012-01-26 09:41:43 -08:00
David Peter
ee013a503d Fix bug where reset_counters resets the wrong counter cache.
If a model belongs_to two associations with the same class, then reset_counters
will reset the wrong counter cache.

Finding the right reflection should use the foreign_key instead, which should
be unique.
2012-01-16 19:06:45 -08:00
Dmitry Polushkin
04bc40ff50 Merge branch 'master' of git://github.com/rails/rails 2011-12-31 01:10:42 +00:00
Alexey Muranov
6468ff4197 Test fixtures with custom model and table names
Test using fixtures with random names and model names, that is not following naming conventions but using set_fixture_class instead.

It is expected that the table name be defined in the model, but this is not explicitly tested here.  This will need to be fixed.
2011-12-30 10:34:01 +01:00
Jon Leighton
dae7b65453 Support establishing connection on ActiveRecord::Model.
This is the 'top level' connection, inherited by any models that include
ActiveRecord::Model or inherit from ActiveRecord::Base.
2011-12-28 18:27:41 +00:00
Jon Leighton
649869557a Fixtures support for ActiveRecord::Model 2011-12-24 11:08:15 +00:00
Jon Leighton
6af7192af5 I herd you like modules. 2011-12-24 11:08:15 +00:00
Alvaro Bautista
30ce084bbf serialize fails on subclass 2011-12-23 18:19:25 +00:00
David Heinemeier Hansson
85b64f98d1 Added ActiveRecord::Base.store for declaring simple single-column key/value stores [DHH] 2011-10-13 16:24:22 -05:00
Joseph Palermo
c90e5ce779 Only use LOWER for mysql case insensitive uniqueness check when column has a case sensitive collation. 2011-10-09 13:14:07 -07:00