Yii Framework Forum: relation with findByAttributes - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

relation with findByAttributes Rate Topic: -----

#1 User is offline   faris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 18-December 11

Posted 18 April 2012 - 02:17 AM

Post::model()->with('author','comments')->findAll();

is that possible to do that way like this ?

Post::model()->with('author')->findbyPk($id)->author_name;
it will return value of "author_name"

but i tried it and return nothing ??

can you give me a solution ?
0

#2 User is offline   alexFidelis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 17-November 11

Posted 18 April 2012 - 10:29 PM

View Postfaris, on 18 April 2012 - 02:17 AM, said:

Post::model()->with('author','comments')->findAll();

is that possible to do that way like this ?

Post::model()->with('author')->findbyPk($id)->author_name;
it will return value of "author_name"

but i tried it and return nothing ??

can you give me a solution ?



just do $model=Post::model()->findAll()
in the view
foreach($model as $post){
echo $post->author->author_name
foreach($post->comments as $comment){
echo $comment
}
}
0

#3 User is offline   faris 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 18-December 11

Posted 21 April 2012 - 03:27 AM

View PostalexFidelis, on 18 April 2012 - 10:29 PM, said:

just do $model=Post::model()->findAll()
in the view
foreach($model as $post){
echo $post->author->author_name
foreach($post->comments as $comment){
echo $comment
}
}


Yes you right, but i thhought that i can call the attr with the quick way like what i said,
but indeed thats what i mean . .

Thanx Alex :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users