One of my modesl looks like this: class UnprocessedPage < ActiveRecord::Base has_one :user attr_accessible :url, :user_id end Do I need :user_id? Or is it implied via "has_one :user"? This is working as is.. but when I look for examples of other things, I never see any attributes with *_id... so I''m wondering if it''s implied and I''m just mucking things up? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/K4kU3dSf728J. For more options, visit https://groups.google.com/groups/opt_out.
On 9 December 2012 20:25, Dan Brooking <dmbrooking-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> One of my modesl looks like this: > > class UnprocessedPage < ActiveRecord::Base > has_one :user > attr_accessible :url, :user_id > end > > Do I need :user_id? Or is it implied via "has_one :user"?You should not have a user_id column in the database for a has_one association. If UnprocessedPage has_one :user then User belongs_to :unprocessed_page and User should have an unprocessed_page_id column. Are you sure you do not mean User has_many :unprocessed_pages and UnprocessedPage belongs_to :user? Have a look at the Rails Guide on ActiveRecord Associations for more details and if you have not already done so then work right through a good rails tutorial such as railstutorial.org, which is free to use online, in order to get the basics of Rails. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
OK, yeah you are right. It shouldn''t be has_one. It sounds like the associated you mentioned is the one I''m looking for. With that said, would I still have a user_id column? or would that be implicit via the belongs_to? On Sun, Dec 9, 2012 at 4:57 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 December 2012 20:25, Dan Brooking <dmbrooking-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > One of my modesl looks like this: > > > > class UnprocessedPage < ActiveRecord::Base > > has_one :user > > attr_accessible :url, :user_id > > end > > > > Do I need :user_id? Or is it implied via "has_one :user"? > > You should not have a user_id column in the database for a has_one > association. If UnprocessedPage has_one :user then User belongs_to > :unprocessed_page and User should have an unprocessed_page_id column. > Are you sure you do not mean User has_many :unprocessed_pages and > UnprocessedPage belongs_to :user? > > Have a look at the Rails Guide on ActiveRecord Associations for more > details and if you have not already done so then work right through a > good rails tutorial such as railstutorial.org, which is free to use > online, in order to get the basics of Rails. > > Colin > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 9 December 2012 22:22, Dan Brooking <dmbrooking-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OK, yeah you are right. It shouldn''t be has_one. It sounds like the > associated you mentioned is the one I''m looking for. With that said, would > I still have a user_id column? or would that be implicit via the belongs_to?Using belongs_to implies that you must provide a user_id column in the database. As I said, work through the tutorial and study the guides and all will become clear (well, less muddy at least). Colin> > > On Sun, Dec 9, 2012 at 4:57 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 9 December 2012 20:25, Dan Brooking <dmbrooking-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > One of my modesl looks like this: >> > >> > class UnprocessedPage < ActiveRecord::Base >> > has_one :user >> > attr_accessible :url, :user_id >> > end >> > >> > Do I need :user_id? Or is it implied via "has_one :user"? >> >> You should not have a user_id column in the database for a has_one >> association. If UnprocessedPage has_one :user then User belongs_to >> :unprocessed_page and User should have an unprocessed_page_id column. >> Are you sure you do not mean User has_many :unprocessed_pages and >> UnprocessedPage belongs_to :user? >> >> Have a look at the Rails Guide on ActiveRecord Associations for more >> details and if you have not already done so then work right through a >> good rails tutorial such as railstutorial.org, which is free to use >> online, in order to get the basics of Rails. >> >> Colin >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.