#278: HABTM 'order' still doesn't work
--------------------+-------------------------------------------------------
Reporter: tosick | Type: defect
Status: new | Priority: blocker
Milestone: 1.3.0 | Component: Active Record
Keywords: |
--------------------+-------------------------------------------------------
Example:
podcasts habtm artists
== Artists: ==
{{{
CREATE TABLE `artists` (
`id` int(11) NOT NULL auto_increment,
`en_name` varchar(255) default NULL,
`ru_name` varchar(255) default NULL,
`en_brief` longtext,
`ru_brief` longtext,
`en_biography` longtext,
`ru_biography` longtext,
`is_releases_visible` tinyint(1) NOT NULL default '0',
`is_charts_visible` tinyint(1) NOT NULL default '0',
`is_events_visible` tinyint(1) NOT NULL default '0',
`is_podcasts_visible` tinyint(1) NOT NULL default '0',
`position` int(11) default NULL,
`updated_at` datetime default NULL,
`created_at` datetime default NULL,
`en_presskit` varchar(255) default NULL,
`ru_presskit` varchar(255) default NULL,
`has_presskit` tinyint(1) NOT NULL,
`weight` int(11) NOT NULL default '1',
PRIMARY KEY (`id`),
KEY `idx_artists_is_releases_visible` (`is_releases_visible`),
KEY `idx_artists_is_charts_visible` (`is_charts_visible`),
KEY `idx_artists_is_events_visible` (`is_events_visible`),
KEY `idx_artists_is_podcasts_visible` (`is_podcasts_visible`),
KEY `idx_artists_weight` (`weight`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8
}}}
model description:
{{{
class Artist extends ActiveRecord
{
public $has_and_belongs_to_many = array(
'podcasts' => array(
'class_name' => 'Podcast',
'conditions' => 'd <= NOW() AND is_active=1',
'unique' => true,
'order' => 'd DESC'
)
);
}
}}}
== Podcasts: ==
{{{
CREATE TABLE `podcasts` (
`id` int(11) NOT NULL auto_increment,
`url` varchar(255) default NULL,
`en_name` varchar(255) default NULL,
`ru_name` varchar(255) default NULL,
`d` datetime default NULL,
`length` datetime default NULL,
`en_description` longtext,
`ru_description` longtext,
`downloaded` int(11) NOT NULL,
`updated_at` datetime default NULL,
`created_at` datetime default NULL,
`size` int(11) default NULL,
`is_active` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8
}}}
Model description:
{{{
class Podcast extends ActiveRecord
{
public $has_and_belongs_to_many = array(
'artists' => array(
'class_name' => 'Artist',
'unique' => true,
'order' => 'weight, en_name'
)
);
}
}}}
== Problem ==
On select from podcasts everything goes fine:
{{{
SELECT artists.* FROM artists
LEFT OUTER JOIN artists_podcasts AS _ArtistPodcast ON
_ArtistPodcast.artist_id =
artists.id
LEFT OUTER JOIN podcasts AS _Podcast ON _ArtistPodcast.podcast_id =
_Podcast.id
WHERE _ArtistPodcast.podcast_id = 19
ORDER BY weight, en_name
}}}
On podcast update (after update podcasts table) error is occured:
{{{
SELECT artists.* FROM artists
LEFT OUTER JOIN artists_podcasts AS _ArtistPodcast ON
_ArtistPodcast.artist_id =
artists.id
LEFT OUTER JOIN podcasts AS _Podcast ON _ArtistPodcast.podcast_id =
_Podcast.id
WHERE _ArtistPodcast.podcast_id = 19
ORDER BY artists.weight, artists.en_name ORDER BY artists.weight,
artists.en_name ORDER BY artists.weight, artists.en_name
}}}
{{{
SQL Error: [1064] You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near 'ORDER BY artists.weight, artists.en_name ORDER BY artists.weight,
artists.en_nam' at line 1
}}}
--
Ticket URL: <
http://trac.akelos.org/ticket/278>
Akelos PHP Framework <
http://www.akelos.org/>
Akelos PHP Framework