I'm confused as to how Relational Active Record works.
If I have several relationships between tables defined and I want a single row of data that crosses these tables. The documentation leads me to think that:
a ) The lazy loading approach makes a separate db call against each table to fetch the data.
b ) The eager loading approach brings back all the data using an outer join and then narrows the result down in the code.
Is this correct? If so it seems very wasteful of resources for large DB's, so I think I am wrong.
Assuming I have created all the models for each class and defined the relationships between the primary keys, how would I recreate the following query using Relational Active Record?
SELECT access.access_id FROM access INNER JOIN site ON access.site_id = site.site_id INNER JOIN user ON access.user_id = user.user_id WHERE site.domain = :domain AND user.username = :username;
Here is the table structure:
CREATE TABLE IF NOT EXISTS `access` ( `access_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `site_id` int(11) NOT NULL, PRIMARY KEY (`site_access_id`), ); CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(128) NOT NULL, PRIMARY KEY (`user_id`) ); CREATE TABLE IF NOT EXISTS `site` ( `site_id` int(11) NOT NULL AUTO_INCREMENT, `domain` varchar(128) NOT NULL, PRIMARY KEY (`site_id`) );
Edit: Forgot to mention that all the joins are one primary key to many.