On 4.10.2010, at 4.43, pmf015 wrote:
> Hello.
>
> I've encountered strange error while running the integration test on
> page 118, and I could really use some help.
>
> ActiveRecord::StatementInvalid (Mysql::Error: Unknown column
> 'komponentas_proizvodjacs.komponentum_id' in 'on clause': SELECT
> count(DISTINCT komponentas.id) AS count_all FROM komponentas LEFT
> OUTER JOIN
> komponentas_proizvodjacs ON komponentas_proizvodjacs.komponentum_id =
> komponentas.id LEFT OUTER JOIN proizvodjacs ON proizvodjacs.id =
> komponentas_proizvodjacs.proizvodjac_id LEFT OUTER JOIN kategorijas
> ON kategorijas.id = komponentas.kategorija_id ):
This means that there is no field called komponentum_id in table komponentas_proizvodjacs.
> Since that unknown "..komponentum_id" is autocreated, I don't know how
> to fix it.
What do you mean autocreated? Rails migrations only create the id field automatically (and timestamps if you so choose). You have to create foreign keys yourself.
You can check whether the field really exists by writing this in the mysql command line console:
describe komponentas_proizvodjacs;
Cheers,
//jarkko
--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://odesign.fi
Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven:
http://peepcode.com/products/unobtrusive-prototype-js
> Hi.
>
> Thank You for such promptly reply.
>
> I've only used id's for komponentas and proizvodjacs.
>
> komponentas_proizvodjacs is a join table, and it only has 2 fields:
> komponenta_id and proizvodjac_id
>
> So my guess is that that query should be
> komponentas_proizvodjacs.komponenta_id not ...komponentum_id
Rails (or ActiveRecord, to be precise) uses automatic name inflection
to map between plural words (table names, for example) and singular
words (class name, foreign key name). So unless you state otherwise,
Rails assumes the foreign key name is the name of the corresponding
table in singular + _id. So if your table name is komponentas, Rails
tries to change that to singular. Generally (and obviously) Rails uses
English grammar but since English has many words from Latin, there are
some inflections that assume words are in Latin. It seems like in your
case it assumes that the singular form of komponentas is komponentum.
There are two ways around this. In greenfield projects, I would
generally advise to use English names for everything. It will save you
from many headaches like this and has an added benefit of not
restricting your code to speakers of your native language.
If you can't (or don't want to) change that, you can add your own
inflections to your Rails project: http://apidock.com/rails/ActiveSupport/Inflector/Inflections
Please be aware that the exact syntax may be different depending on
your Rails version.
Just to be clear, this has nothing to do with using :include in
queries. You should hit the same problem whenever you use the
association between komponentas and proizvodjac (such as
@komponenta.proizvodjacs).
Cheers,
//jarkko
>
> I don't know should I use table and fields names that are a bit
> shorter.
>
> Anyway, I've moved over that error by removing :proizvodjacs from that
> include.
> I know it's not great and that it will increase number of queries, but
> the performance is not that important, at least not for the moment.
>
> Still, I would like to know what is wrong with that :include thing and
> how to fix it.
>
> Thank You for Your time.
>
> Cheers.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Beginning Ruby on Rails E-Commerce" group.
> To post to this group, send email to railsec...@googlegroups.com.
> To unsubscribe from this group, send email to railsecommerc...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/railsecommerce?hl=en
> .
>
--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com