Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5210 [BLOCKED] Custom field type cleanup (fix deprecation warnings) #5121

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5dd7e98
- Prefer defining field type value as a symbol rather than a class. (…
johnnyshields Jan 1, 2022
fca40d2
Fix deprecation + add release notes
johnnyshields Jan 1, 2022
21d7fcd
Improve docs primarily for the "Fields" page, as well as a few small …
johnnyshields Jan 1, 2022
db541db
One more fix
johnnyshields Jan 1, 2022
a8870d4
Merge branch 'custom-field-type-support' into improve-field-documention
johnnyshields Jan 1, 2022
d65cdcc
One more change
johnnyshields Jan 1, 2022
0fdb6b6
Fix field types
johnnyshields Jan 1, 2022
f7275ed
Merge remote-tracking branch 'remotes/johnnyshields/improve-field-doc…
johnnyshields Jan 1, 2022
83d37c3
Add spec for InvalidFieldType
johnnyshields Jan 1, 2022
b231317
Fix broken spec
johnnyshields Jan 1, 2022
fba73df
Remove usages of field :type as a Class; convert to Symbol everywhere…
johnnyshields Jan 1, 2022
22222c6
- Prefer defining field type value as a Symbol rather than a Class. (…
johnnyshields Apr 5, 2022
3cf2f23
Merge remote-tracking branch 'remotes/origin/master' into custom-fiel…
johnnyshields Apr 13, 2022
0bdffeb
Merge branch 'master' into custom-field-type-support
johnnyshields May 3, 2022
6fe4343
Revert change
johnnyshields May 3, 2022
39d2988
Fix spec
johnnyshields May 5, 2022
6147e80
Update fields.rb
johnnyshields May 5, 2022
3a7128e
Fix spec
johnnyshields May 5, 2022
f7923cf
Merge branch 'custom-field-type-support' of https://github.com/johnny…
johnnyshields May 5, 2022
9ecb812
Merge remote-tracking branch 'remotes/johnnyshields/custom-field-type…
johnnyshields May 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ child elements.

class Person
include Mongoid::Document
field :username, type: String
field :username, type: :string
has_many :cats, primary_key: "username"
end

Expand Down Expand Up @@ -877,7 +877,7 @@ child elements.

class Event
include Mongoid::Document
field :created_at, type: DateTime
field :created_at, type: :date_time
index({ created_at: 1 }, { expire_after_seconds: 3600 })
end

Expand Down Expand Up @@ -1698,7 +1698,7 @@ child elements.

class Band
include Mongoid::Document
field :name, type: String
field :name, type: :string
end

Band.attribute_names
Expand All @@ -1718,7 +1718,7 @@ child elements.

class User
include Mongoid::Document
field :name, type: String
field :name, type: :string
embeds_many :prefs, class_name: "Preference", store_as: 'my_preferences'
end

Expand Down Expand Up @@ -1750,7 +1750,7 @@ child elements.

class Band
include Mongoid::Document
field :name, type: String, default: "New"
field :name, type: :string, default: "New"
end

band = Band.first
Expand Down Expand Up @@ -1811,7 +1811,7 @@ child elements.

class Rule
include Mongoid::Document
field :pattern, type: Regexp, default: /[^abc]/
field :pattern, type: :regexp, default: /[^abc]/
end

* \#1714/\#1706 Added better logging on index creation. (Hans Hasselberg)
Expand Down Expand Up @@ -2069,7 +2069,7 @@ child elements.

class Person
include Mongoid::Document
field :title, type: String
field :title, type: :string
end

Person.new.age = 50 # raises the UnknownAttribute error.
Expand All @@ -2079,8 +2079,8 @@ child elements.

class Band
include Mongoid::Document
field :name, type: String
field :genre, type: String
field :name, type: :string
field :genre, type: :string

attr_readonly :name, :genre
end
Expand Down Expand Up @@ -2114,7 +2114,7 @@ child elements.

class Band
include Mongoid::Document
field :name, type: String
field :name, type: :string

index({ name: 1 }, { unique: true, background: true })
end
Expand All @@ -2123,7 +2123,7 @@ child elements.

class Venue
include Mongoid::Document
field :location, type: Array
field :location, type: :array

index location: "2d"
end
Expand Down Expand Up @@ -2202,7 +2202,7 @@ child elements.

class Band
include Mongoid::Document
field :_id, type: String, default: ->{ name }
field :_id, type: :string, default: ->{ name }
end

To have the default applied *before* other attributes, set `:pre_processed`
Expand All @@ -2211,7 +2211,7 @@ child elements.
class Band
include Mongoid::Document
field :_id,
type: String,
type: :string,
pre_processed: true,
default: ->{ BSON::ObjectId.new.to_s }
end
Expand Down
51 changes: 27 additions & 24 deletions docs/reference/associations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ in order for it to work properly.

class Label
include Mongoid::Document
field :name, type: String
field :name, type: :string
embedded_in :band
end

Expand Down Expand Up @@ -478,7 +478,7 @@ the association in order for it to work properly.

class Album
include Mongoid::Document
field :name, type: String
field :name, type: :string
embedded_in :band
end

Expand Down Expand Up @@ -521,7 +521,7 @@ children via ``parent_`` and ``child_`` methods.

class Tag
include Mongoid::Document
field :name, type: String
field :name, type: :string
recursively_embeds_many
end

Expand Down Expand Up @@ -573,13 +573,13 @@ help of MongoDB projection operation:

class Band
include Mongoid::Document
field :started_on, type: Date
field :started_on, type: :date
embeds_one :label
end

class Label
include Mongoid::Document
field :name, type: String
field :name, type: :string
embedded_in :band
end

Expand Down Expand Up @@ -657,19 +657,19 @@ following models:
include Mongoid::Document
embeds_many :tours
embeds_many :awards
field :name, type: String
field :name, type: :string
end

class Tour
include Mongoid::Document
embedded_in :band
field :year, type: Integer
field :year, type: :integer
end

class Award
include Mongoid::Document
embedded_in :band
field :name, type: String
field :name, type: :string
end

To retrieve bands based on tour attributes, use the dot notation as follows:
Expand Down Expand Up @@ -791,7 +791,7 @@ and remove the default value:
include Mongoid::Document

embedded_in :order

field :_id, type: Object
end

Expand Down Expand Up @@ -951,16 +951,19 @@ association:

class Company
include Mongoid::Document
field :c, type: String
field :c, type: :string
has_many :emails, foreign_key: 'c_ref', primary_key: 'c'
end

class Email
include Mongoid::Document

# This definition of c_ref is automatically generated by Mongoid:
# field :c_ref, type: Object
# field :c_ref, type: :object

# But the type can also be specified:
field :c_ref, type: String
field :c_ref, type: :string

belongs_to :company, foreign_key: 'c_ref', primary_key: 'c'
end

Expand Down Expand Up @@ -988,8 +991,8 @@ An example might make this more clear:
class Company
include Mongoid::Document

field :c_id, type: Integer
field :e_ids, type: Array
field :c_id, type: :integer
field :e_ids, type: :array

has_and_belongs_to_many :employees,
primary_key: :e_id, foreign_key: :e_ids,
Expand All @@ -999,8 +1002,8 @@ An example might make this more clear:
class Employee
include Mongoid::Document

field :e_id, type: Integer
field :c_ids, type: Array
field :e_id, type: :integer
field :c_ids, type: :array

has_and_belongs_to_many :companies,
primary_key: :c_id, foreign_key: :c_ids,
Expand Down Expand Up @@ -1154,7 +1157,7 @@ polymorphic association:
class Product
include Mongoid::Document

field :name, type: String
field :name, type: :string
has_and_belongs_to_many :bundles

embeds_many :prices, as: :item
Expand All @@ -1163,7 +1166,7 @@ polymorphic association:
class Bundle
include Mongoid::Document

field :name, type: String
field :name, type: :string
has_and_belongs_to_many :products

embeds_many :prices, as: :item
Expand Down Expand Up @@ -1419,7 +1422,7 @@ be touched on the parent association in addition to updated_at:
class Label
include Mongoid::Document
include Mongoid::Timestamps
field :bands_updated_at, type: Time
field :bands_updated_at, type: :time
has_many :bands
end

Expand Down Expand Up @@ -1654,19 +1657,19 @@ referenced associations:
include Mongoid::Document
has_many :tours
has_many :awards
field :name, type: String
field :name, type: :string
end

class Tour
include Mongoid::Document
belongs_to :band
field :year, type: Integer
field :year, type: :integer
end

class Award
include Mongoid::Document
belongs_to :band
field :name, type: String
field :name, type: :string
end

To retrieve bands that toured since 2000 and have at least one award, one
Expand Down Expand Up @@ -1729,7 +1732,7 @@ For example, given the following models:
include Mongoid::Document

embeds_many :participants

field :name, type: String
field :states, type: Array
end
Expand All @@ -1738,7 +1741,7 @@ For example, given the following models:
include Mongoid::Document

embedded_in :tour

field :name, type: String
end

Expand Down
8 changes: 4 additions & 4 deletions docs/reference/callbacks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ for cross-cutting concerns, like queueing up background jobs.

class Article
include Mongoid::Document
field :name, type: String
field :body, type: String
field :slug, type: String
field :name, type: :string
field :body, type: :string
field :slug, type: :string

before_create :send_message

Expand All @@ -75,7 +75,7 @@ syntax as well:

class Article
include Mongoid::Document
field :name, type: String
field :name, type: :string

set_callback(:create, :before) do |document|
# Message sending code here.
Expand Down
10 changes: 5 additions & 5 deletions docs/reference/crud.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ are not invoked.
class Post
include Mongoid::Document

field :metadata, type: Hash
field :metadata, type: :hash
end

post = Post.create!
Expand All @@ -447,7 +447,7 @@ are not invoked.

embedded_in :flight

field :route, type: String
field :route, type: :string
end

flight = Flight.create!
Expand Down Expand Up @@ -839,7 +839,7 @@ the database up to the time it is saved. Any persistence operation clears the ch

class Person
include Mongoid::Document
field :name, type: String
field :name, type: :string
end

person = Person.first
Expand Down Expand Up @@ -919,7 +919,7 @@ For example, adding to a set like this does not work:
class Band
include Mongoid::Document

field :tours, type: Set
field :tours, type: :set
end

band = Band.new
Expand All @@ -939,7 +939,7 @@ back to the model as follows:
class Band
include Mongoid::Document

field :tours, type: Set
field :tours, type: :set
end

band = Band.new
Expand Down
Loading