Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-916: many to one #5444

Closed
doctrinebot opened this issue Dec 7, 2010 · 6 comments
Closed

DDC-916: many to one #5444

doctrinebot opened this issue Dec 7, 2010 · 6 comments
Assignees
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user mungiu:

First i describe my tables. I have hotel, hotel_type, room, room_type. I use native query for retrive the result. So hotel have many to one with hotel_type, and room with room_type. So the problem i can do for example $room->getRoomType()->getTip(), but i can't do $hotel[0]->getHotelType()->getTip(). Sorry if this is't a bug but i can't explain why many to one for room works and for hotel not. If you need any other information i be glad to provide.

In model i have:

/****
* @var HotelType
*
* @manytoone(targetEntity="Application_Model_HotelType")
* @JoinColumns({
* @joincolumn(name="hotel_type", referencedColumnName="id")
* })
*/
private $hotelType;

@doctrinebot
Copy link
Author

Comment created by @beberlei:

I need the full mapping of both Hotel and HotelType regarding the $hotelType and the sql schema, additionally i need the full error message with stack trace that happens in the query.

@doctrinebot
Copy link
Author

Comment created by mungiu:

This is the model and sql

When i decomment hotel_type mapping i receive this

Message: Unknown column type requested.
Stack trace:

#0 D:\wamp\www\find-booking\library\Doctrine\DBAL\Types\Type.php(141): Doctrine\DBAL\DBALException::unknownColumnType(NULL)
#1 D:\wamp\www\find-booking\library\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(184): Doctrine\DBAL\Types\Type::getType(NULL)
#2 D:\wamp\www\find-booking\library\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(255): Doctrine\ORM\Internal\Hydration\AbstractHydrator->_gatherRowData(Array, Array, Array, Array)
#3 D:\wamp\www\find-booking\library\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(127): Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateRow(Array, Array, Array)
#4 D:\wamp\www\find-booking\library\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(99): Doctrine\ORM\Internal\Hydration\ObjectHydrator->_hydrateAll()
#5 D:\wamp\www\find-booking\library\Doctrine\ORM\AbstractQuery.php(536): Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(Object(Doctrine\DBAL\Statement), Object(Doctrine\ORM\Query\ResultSetMapping), Array)
#6 D:\wamp\www\find-booking\library\Doctrine\ORM\AbstractQuery.php(366): Doctrine\ORM\AbstractQuery->execute(Array, 1)
#7 D:\wamp\www\find-booking\application\controllers\HotelsController.php(243): Doctrine\ORM\AbstractQuery->getResult()
#8 D:\wamp\www\find-booking\library\Zend\Controller\Action.php(513): HotelsController->searchAction()
#9 D:\wamp\www\find-booking\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('searchAction')
#10 D:\wamp\www\find-booking\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#11 D:\wamp\www\find-booking\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#12 D:\wamp\www\find-booking\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#13 D:\wamp\www\find-booking\public\index.php(26): Zend_Application->run()

And what i say i can acces many to one for room as getRoomType->getTip); bit not getHotelType->getTip()

$rsm = new Doctrine\ORM\Query\ResultSetMapping;
$rsm->addEntityResult('Application_Model_Hotel', 'h');
$rsm->addEntityResult('Application_Model_Room', 'r');
$rsm->addFieldResult('h', 'id', 'id');
//$rsm->addFieldResult('h', 'hotel_type', 'hotel_type');
$rsm->addFieldResult('h', 'denumire', 'denumire');
//$rsm->addFieldResult('h', 'rooms', 'rooms');
$rsm->addJoinedEntityResult('Application_Model_Review', 'w', 'h', 'reviews');
$rsm->addFieldResult('w', 'turist', 'turist');
//$rsm->addJoinedEntityResult('Application_Model_Booking', 'b', 'r', 'bookings');
//$rsm->addJoinedEntityResult('Application_Model_RoomPrice', 'p', 'r', 'roomPrices');
//$rsm->addJoinedEntityResult('Application_Model_RoomType', 't', 'r', 'roomType');
$rsm->addScalarResult('camere_libere', 'camere_libere');
$rsm->addScalarResult('camera', 'camera');
$rsm->addScalarResult('preturi', 'preturi');

$query = $this->em->createNativeQuery("SELECT
camere_libere_view.
,
GROUP_CONCAT(r2_.room) as camera,
GROUP_CONCAT(coalesce(r2_.price, 'ask')) as price,
GROUP_CONCAT(r2_.from_date) as from_date,
GROUP_CONCAT(r2_.to_date) as to_date,
count(r2_.id) AS cate_preturi_sunt
FROM
(SELECT
h0_.,
r1
.id AS id1,
r1_.total_camere AS total_camere4,
COALESCE(sum(b3_.numar_camere),0) AS numar_camere_rezervate,
r1_.total_camere-COALESCE(sum(b3_.numar_camere),0) AS camere_libere,
count(b3_.id) AS sclr7
FROM
hotel h0_,
room r1* LEFT JOIN booking b3*
ON r1_.id = b3_.room
WHERE
h0_.id = r1_.hotel
GROUP BY
r1_.id) camere_libere_view
LEFT JOIN room_price r2_
ON id1 = r2_.room
GROUP BY
id", $rsm);


-- Table structure for table hotel

CREATE TABLE IF NOT EXISTS hotel (
id int(11) NOT NULL AUTO_INCREMENT,
hotel_type int(11) NOT NULL,
tara varchar(100) NOT NULL,
oras varchar(100) NOT NULL,
denumire varchar(100) NOT NULL,
descriere text NOT NULL,
stele tinyint(5) NOT NULL,
adresa varchar(100) NOT NULL,
zip varchar(10) NOT NULL,
telefon varchar(20) NOT NULL,
fax varchar(20) NOT NULL,
locatie varchar(300) NOT NULL,
detalii_locatie text,
distance*from*centre int(11) NOT NULL,
lat int(11) DEFAULT NULL,
lon int(11) DEFAULT NULL,
meal_type varchar(100) NOT NULL,
facilitati_hotel varchar(1000) NOT NULL,
servicii_hotel varchar(1000) DEFAULT NULL,
currency varchar(5) NOT NULL,
check*in*hour varchar(20) NOT NULL COMMENT 'politica hotel',
check*out*hour varchar(20) NOT NULL COMMENT 'politica hotel',
cancellation*with*charged int(11) NOT NULL COMMENT 'politica hotel',
exterior varchar(300) DEFAULT NULL,
poster varchar(20) DEFAULT NULL,
video varchar(20) DEFAULT NULL,
top_ten int(11) DEFAULT NULL COMMENT 'daca apare pe prima pagina',
informatii varchar(500) DEFAULT NULL,
agency_id int(11) NOT NULL,
PRIMARY KEY (id),
KEY hotel*type (hotel*type)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2330 ;


-- Table structure for table hotel_type

CREATE TABLE IF NOT EXISTS hotel_type (
id int(11) NOT NULL AUTO_INCREMENT,
tip varchar(100) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


-- Table structure for table room

CREATE TABLE IF NOT EXISTS room (
id int(11) NOT NULL AUTO_INCREMENT,
hotel_type int(11) NOT NULL,
hotel int(11) NOT NULL,
room_type int(11) NOT NULL,
completare_tip varchar(100) DEFAULT NULL,
numar_persoane int(11) NOT NULL,
descriere_camera text NOT NULL,
inclus*in*pret varchar(300) DEFAULT NULL,
total_camere int(11) NOT NULL,
PRIMARY KEY (id),
KEY camera (room_type),
KEY id_hotel (hotel)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;


-- Table structure for table room_price

CREATE TABLE IF NOT EXISTS room_price (
id int(11) NOT NULL AUTO_INCREMENT,
room int(11) NOT NULL,
from_date date NOT NULL,
to_date date NOT NULL,
price int(11) DEFAULT NULL,
disccount float DEFAULT NULL,
PRIMARY KEY (id),
KEY room (room)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

@doctrinebot
Copy link
Author

Comment created by @beberlei:

This is not a bug, you have the mapping wrong. The error message clearly points you to your mistake. One of the ->addEntityField calls has a non-existant/wrong field.

@doctrinebot
Copy link
Author

Comment created by mungiu:

But, the field exist, how to mapping in another way? HOw is my mistake, if the model is corect and the field exist in database? How come if i put for example $rsm->addFieldResult('h', 'denumire_x', 'denumire_x'); and denumire_x doesn exist don=t dhow me any warning and if i put that field who exist give that error?

@doctrinebot
Copy link
Author

Comment created by mungiu:

Sorry you can close again , you right the mapping cause that, i understand now when to use field result and when to use meta result.. Tanks for take your time. Apologize.

@doctrinebot
Copy link
Author

Issue was closed with resolution "Fixed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants