[Ror-es] Duda sobre foreign keys
Jose Ferrer
jferrer at udeconsultores.com
Wed Sep 20 08:12:18 GMT 2006
Tengo una tabla con ofertas de coches:
car_offers (id, make_id, model_id...)
Y otra con marcas de coches:
makes (id, name)
Mi pregunta es que tengo que hacer exactamente para, al listar, poder
poner @car_offers.make.name porque obtengo el error este:
Mysql::Error: Unknown column 'makes.car_offer_id' in 'on clause':
SELECT car_offers.`id` AS t0_r0, car_offers.`make_id` AS t0_r1,
car_offers.`model` AS t0_r2, car_offers.`kilometers` AS t0_r3,
car_offers.`power_in_kw` AS t0_r4, car_offers.`registration_date` AS
t0_r5, car_offers.`price` AS t0_r6, car_offers.`car_body_id` AS
t0_r7, car_offers.`car_type_id` AS t0_r8, car_offers.`fuel_id` AS
t0_r9, car_offers.`transmission_id` AS t0_r10, car_offers.`color_id`
AS t0_r11, car_offers.`door_id` AS t0_r12, car_offers.`cushion` AS
t0_r13, car_offers.`further_vehicle_information` AS t0_r14,
car_offers.`contact_name` AS t0_r15, car_offers.`contact_telephone`
AS t0_r16, car_offers.`contact_mobile` AS t0_r17,
car_offers.`contact_email` AS t0_r18, makes.`id` AS t1_r0,
makes.`name` AS t1_r1 FROM car_offers LEFT OUTER JOIN makes ON
makes.car_offer_id = car_offers.id
Por otro lado, si en el modelo pongo esto:
class CarOffer < ActiveRecord::Base
has_one :make,
:class_name => "CarOffer",
:foreign_key => "make_id"
Obtengo el siguiente error:
You have a nil object when you didn't expect it!
The error occured while evaluating nil.name
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.simplelogica.net/pipermail/ror-es/attachments/20060920/6f92c8cc/attachment-0001.htm
More information about the Ror-es
mailing list