has_many_through NameError: uninitialized constant

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

has_many_through NameError: uninitialized constant

fugee ohu
i=Item.first
i.item_properties
NameError: uninitialized constant Item::ItemProperties

class Item < ApplicationRecord
 has_many :boxes
 has_many :item_pictures
 has_many :pictures, through: :item_pictures
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :item_properties, through: :item_item_properties
 ITEM_TYPES =  ['General', 'Book', 'Record', 'Magazine', 'Pez dispenser', 'CD', 'VHS casette']
 validates :item_type, inclusion: ITEM_TYPES
 attr_accessor "Year"
 
end

class ItemItemProperty < ApplicationRecord
 belongs_to :items, primary_key: 'item_type', foreign_key: 'item_type'
 belongs_to :item_properties, primary_key: 'item_type', foreign_key: 'item_type'
end

class ItemProperty < ApplicationRecord
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :items, through: :item_item_properties
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: has_many_through NameError: uninitialized constant

Ariel Juodziukynas
ItemItemProperty is wrong, belongs_to association should be singular not plural: belongs_to :item and belongs_to :item_property

El lun., 21 oct. 2019 08:27, fugee ohu <[hidden email]> escribió:
i=Item.first
i.item_properties
NameError: uninitialized constant Item::ItemProperties

class Item < ApplicationRecord
 has_many :boxes
 has_many :item_pictures
 has_many :pictures, through: :item_pictures
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :item_properties, through: :item_item_properties
 ITEM_TYPES =  ['General', 'Book', 'Record', 'Magazine', 'Pez dispenser', 'CD', 'VHS casette']
 validates :item_type, inclusion: ITEM_TYPES
 attr_accessor "Year"
 
end

class ItemItemProperty < ApplicationRecord
 belongs_to :items, primary_key: 'item_type', foreign_key: 'item_type'
 belongs_to :item_properties, primary_key: 'item_type', foreign_key: 'item_type'
end

class ItemProperty < ApplicationRecord
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :items, through: :item_item_properties
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcDnGXb00NWse8cUqW%2B_W2qk84UGXAxnOKZVqMFPdbGoUw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: has_many_through NameError: uninitialized constant

fugee ohu


On Monday, October 21, 2019 at 7:31:36 AM UTC-4, Ariel Juodziukynas wrote:
ItemItemProperty is wrong, belongs_to association should be singular not plural: belongs_to :item and belongs_to :item_property

El lun., 21 oct. 2019 08:27, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> escribió:
i=Item.first
i.item_properties
NameError: uninitialized constant Item::ItemProperties

class Item < ApplicationRecord
 has_many :boxes
 has_many :item_pictures
 has_many :pictures, through: :item_pictures
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :item_properties, through: :item_item_properties
 ITEM_TYPES =  ['General', 'Book', 'Record', 'Magazine', 'Pez dispenser', 'CD', 'VHS casette']
 validates :item_type, inclusion: ITEM_TYPES
 attr_accessor "Year"
 
end

class ItemItemProperty < ApplicationRecord
 belongs_to :items, primary_key: 'item_type', foreign_key: 'item_type'
 belongs_to :item_properties, primary_key: 'item_type', foreign_key: 'item_type'
end

class ItemProperty < ApplicationRecord
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :items, through: :item_item_properties
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com.

 

Could not find the source association(s) "item_property" or :item_properties in model ItemItemProperty. Try 'has_many :item_properties, :through => :item_item_properties, :source => <name>'. Is it one of item or item_propertie?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f0b15f89-7706-45a7-b7d5-60a31fa631ca%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: has_many_through NameError: uninitialized constant

fugee ohu
In reply to this post by Ariel Juodziukynas


On Monday, October 21, 2019 at 7:31:36 AM UTC-4, Ariel Juodziukynas wrote:
ItemItemProperty is wrong, belongs_to association should be singular not plural: belongs_to :item and belongs_to :item_property

El lun., 21 oct. 2019 08:27, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> escribió:
i=Item.first
i.item_properties
NameError: uninitialized constant Item::ItemProperties

class Item < ApplicationRecord
 has_many :boxes
 has_many :item_pictures
 has_many :pictures, through: :item_pictures
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :item_properties, through: :item_item_properties
 ITEM_TYPES =  ['General', 'Book', 'Record', 'Magazine', 'Pez dispenser', 'CD', 'VHS casette']
 validates :item_type, inclusion: ITEM_TYPES
 attr_accessor "Year"
 
end

class ItemItemProperty < ApplicationRecord
 belongs_to :items, primary_key: 'item_type', foreign_key: 'item_type'
 belongs_to :item_properties, primary_key: 'item_type', foreign_key: 'item_type'
end

class ItemProperty < ApplicationRecord
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :items, through: :item_item_properties
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com.
 

Could not find the source association(s) "item_property" or :item_properties in model ItemItemProperty. Try 'has_many :item_properties, :through => :item_item_properties, :source => <name>'. Is it one of item or item_propertie?

Is rails as confused as I am? Why does it have "propertie" in the error?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/20fcab20-2009-4a44-9485-14e41ae09a33%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: has_many_through NameError: uninitialized constant

fugee ohu
In reply to this post by Ariel Juodziukynas


On Monday, October 21, 2019 at 7:31:36 AM UTC-4, Ariel Juodziukynas wrote:
ItemItemProperty is wrong, belongs_to association should be singular not plural: belongs_to :item and belongs_to :item_property

El lun., 21 oct. 2019 08:27, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> escribió:
i=Item.first
i.item_properties
NameError: uninitialized constant Item::ItemProperties

class Item < ApplicationRecord
 has_many :boxes
 has_many :item_pictures
 has_many :pictures, through: :item_pictures
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :item_properties, through: :item_item_properties
 ITEM_TYPES =  ['General', 'Book', 'Record', 'Magazine', 'Pez dispenser', 'CD', 'VHS casette']
 validates :item_type, inclusion: ITEM_TYPES
 attr_accessor "Year"
 
end

class ItemItemProperty < ApplicationRecord
 belongs_to :items, primary_key: 'item_type', foreign_key: 'item_type'
 belongs_to :item_properties, primary_key: 'item_type', foreign_key: 'item_type'
end

class ItemProperty < ApplicationRecord
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :items, through: :item_item_properties
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com.

 

can't write unknown attribute `item_type`

@item.item_properties << ItemProperty.where(item_type: params[:item_type])

class ItemProperty < ApplicationRecord
has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
has_many :items, through: :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
attr_accessor :item_type
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/163ae6f5-9766-4fed-8ef6-fd6d256472db%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: has_many_through NameError: uninitialized constant

fugee ohu
In reply to this post by Ariel Juodziukynas


On Monday, October 21, 2019 at 7:31:36 AM UTC-4, Ariel Juodziukynas wrote:
ItemItemProperty is wrong, belongs_to association should be singular not plural: belongs_to :item and belongs_to :item_property

El lun., 21 oct. 2019 08:27, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> escribió:
i=Item.first
i.item_properties
NameError: uninitialized constant Item::ItemProperties

class Item < ApplicationRecord
 has_many :boxes
 has_many :item_pictures
 has_many :pictures, through: :item_pictures
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :item_properties, through: :item_item_properties
 ITEM_TYPES =  ['General', 'Book', 'Record', 'Magazine', 'Pez dispenser', 'CD', 'VHS casette']
 validates :item_type, inclusion: ITEM_TYPES
 attr_accessor "Year"
 
end

class ItemItemProperty < ApplicationRecord
 belongs_to :items, primary_key: 'item_type', foreign_key: 'item_type'
 belongs_to :item_properties, primary_key: 'item_type', foreign_key: 'item_type'
end

class ItemProperty < ApplicationRecord
 has_many :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'
 has_many :items, through: :item_item_properties
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="UWg_9pG4AQAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/065ff213-21fe-4b69-a41c-7966bd82a12c%40googlegroups.com.

 In form_for(item) how do i create a text_field for item.item_property.name where item  has_many :item_properties, through: :item_item_properties, primary_key: 'item_type', foreign_key: 'item_type'

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cf4f7fbb-a29f-4d4f-a1ea-83499e09b9cb%40googlegroups.com.