On 24 May 2015 at 02:56, Elizabeth McGurty <emcgur...@gmail.com> wrote:
> Okay... I am really trying to be super vigilant to best Ruby/Ruby on Rails
> practices here... the whole n + 1 matter particularly
>
> I have a parent table called Advertiser:
>
> This is how it looks on the database:
>
> CREATE TABLE advertisers (
>   advertiser_id varchar(40) NOT NULL,

If you are committed to the rails conventions then that should just be
id, not advertiser_id.  advertiser_id should be used in another table
that belongs_to advertiser.

>   title varchar(50) NOT NULL,
>   category_id int(3) NOT NULL DEFAULT '99',
> ...
> class Advertiser < ActiveRecord::Base
>
>   require 'uri'
>
>   self.primary_key = 'advertiser_id'
>   attr_accessor :item_image_upload
>   has_one :item_image
>   has_one :category

You have has_one category, but also a category_id in the table either
it should be belongs_to category or the field should not be there.

> ...
> CREATE TABLE categories (
>   category_id int(3) NOT NULL DEFAULT '99',
>   category_type varchar(50) NOT NULL,
>   KEY category_type_index (category_type)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
>
>
> Categories exists as category.rb, and this is the model:
>
> class Category < ActiveRecord::Base
>
>  self.primary_key = 'category_id'
>
>   belongs_to :advertiser
>   belongs_to :borrower
>   belongs_to :lender

You need _id fields for each of the above.

> ...
>     I am really committed to using best practices.  What an I doing wrong?
> I am not clear as to model requirement regarding look up values that are
> user nonchangeable... The whole notion, for example, has_one with regard to
> a look up is not clear to me.

Have you worked right through a good tutorial such as
railstutorial.org (which is free to use online), including all the
exercises?  That should help to make the basics of rails more clear.

Colin

-- 
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 rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtQj6jz8%2Btd2rHnBGrKO%3Dtj6F9_r_QHqTwBh3if5XqLEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to