If with your query you only hydrate your "blog posts" then that
additional information "get the interest of the user or nothing if no
interest" will just disappear, therefore making your approach
useless...

This is actually a common problem because a common one. My approach
would be the following :

$blog_posts = BlogPostPeer::doSelect();
BlogPostPeer::preloadInterestForUserId($blog_posts, 27);

in BlogPost.php I would create a private array
private $aInterestForUserId = array();

and in BlogPostPeer the following preloading function

public static function preloadInterestForUserId(&$blog_posts,
$user_id)
{
  $blog_post_ids = array();
  foreach ($blog_posts as $key => $blog_post)
  {
    $blog_post_ids[$blog_post->getId()] = $key;
  }
  $criteria = new Criteria();
  $criteria->add(InterestPeer::BlogPostId, array_keys($blog_post_ids),
CRITERIA::IN);
  $criteria->add(InterestPeer::UserId, $user_id);
  $interests = InterestPeer::doSelect($criteria);
  foreach($interests as $interest)
  {
    $blog_posts[$blog_post_ids[$interest->getBlogPostId()]]-
>setInterestForUserId($interest,$user_id);
  }
}

Finally create the setInterestForUserId and getInterestForUserId
functions

Another approach is to do the query and hydrate yourself.

Hope this helps

Fabrice


On Apr 16, 6:47 am, Manoj Ghimire <[EMAIL PROTECTED]> wrote:
> There was some confusion. First let me tell, the suggestion that I got
> above really worked, Thakn you all.
>
> Now to the point, the SQL query I wanted was
>
> SELECT table1.*
> FROM table1
> LEFT JOIN table2 ON (table1.id = table2..table1_id AND table2.user_id=
> '27')
>
> I think I wrote it wrong in the first post table1.user_id = '27', it
> must have been table2.user_id = '27'.
>
> Use:
> I use table1 to list things (say a blog post). Any user can show that
> they liked the post and show interest in it. To store this data I use
> Table2 which has table1_id as foreign key and user_id, the ID of the
> user showing interest. A user can only show his/her interest once, so
> in case of logged in user i want to find if the user has shown
> interest in the post or not. Left JOIN is required because I also want
> the blog posts to be listed on which user has not shown the interest.
>
> Initially I used a component for it, which for every table1 post
> queried the database for the given user_id to the table2. This
> increased the database queries used to build that page very much, so
> had to find this Hack out.
>
> Do I make some sense ?? Did I do it correct ?? Comments ??
>
> Manoj Ghimire
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to