2011-01-10 5 views
2

나는 Kohana ORM으로 그립을 잡으려고 노력하고 있지만 조금 붙어 있습니다. category_id를 기반으로 한 관계로 카테고리 및 게시물 모델을 만들었습니다.Kohana ORM 관계

게시물과 카테고리 모델을 따로 가져올 수는 있지만 관계를 사용하여 가져올 수는 없습니다. 예를 들어 :

// Get first category 
$category = ORM::factory('category', 1); 

foreach ($category->posts as $post) 
{ 
    echo $post->title;     
} 

위의 단지 나에게 빈 화면 제공 (내가 컨트롤러에 아무것도 출력하지 않아야 알고, 그냥 먼저 작업을 진행하려고).

print_r($category); 

나에게주는이 :

Model_Category 객체 ([_has_many : 보호] => 배열 ([게시물] => 배열 ([모델] =이> 게시 [foreign_key] => CATEGORY_ID [통해] = > _rules : protected) => Array() [_Value : protected] => Array() [_validate : protected] => [_rules_one : protected] Array] [_libels : protected] => Array() [_object : protected] => Array ([id] => Array [] [_related : protected] => Array() [_loaded : protected] => [_saved : protected] => 1 [_sorting : 보호] => 배열 ([ID] => category [_ object_plural : protected] => categories [_table_name : protected] => 카테고리 [_table_columns : protected] => 배열 ([id] => ASC) [ordin_position] => 1 [배열] => int [min] => 0 [max] => 65535 [column_name] => id [column_default] => [data_type] => smallint unsigned [is_nullable] PRI [privileges] => 선택, 삽입, 업데이트, 참조) [title] => Array ([type] => string [character_maximum_length()] => 6 [주석] => [추가] => auto_increment [ ] => 65535 [column_name] => 제목 [column_default] => [data_type] => 텍스트 [is_nullable] => [ordinal_position] => 2 [collation_name] => latin1_swedish_ci [comment] => [extra] => [key ]] => [권한] => 선택, 삽입, 업데이트, 참조) [description] => 배열 ([type] => 문자열 [character_maximum_length] => 65535 [column_name] => 설명 [column_default] => [data_type] = > 텍스트 [is_nullable] => [ordinal_position] => 3 [collation_name] => latin1 [_igned_columns : protected] => Array() [_updated_column : protected] => [_created_column : _created_column : _swedish_ci [주석] => [추가] => [키] => 보호 된] => 1 [_db : 보호] => Database_MySQL 객체 ([_ 연결 _ID : 보호됨] => [보호 _] : 보호 된 _ => [_primary_key : ] => d6ad44aa068ae69071b9614f2a4a760bf55d9307 [_identifier : protected] =>category` [_instance : protected] => 기본 [_connection : protected] => 리소스 ID # 36 [_config : protected] => 배열 ([type] => mysql [> connection ] => [charset] => utf8 [캐싱] => [프로파일 링] => 1)) [_db_applied : (_db_builder : protected] => [_with_applied : protected] => Array() [_preload_data : protected] => Array() [_db_pending : protected] 배열())

아무도 도와 줄 수 있습니까?

감사의 말.

감사합니다.

+0

모델 구성 표시 – biakaveron

답변

2

게시물은 관계가 아니라 모음입니다. 관계에 대해 find_all() 또는 find()를 사용하여 레코드 컬렉션을 반환하십시오.

foreach ($category->posts->find_all() as $post) { 
    echo $post->title;     
} 

관계에 다양한 다른 방법을 적용하여 orderby, where 등을 사용하여 반환 된 결과를 필터링 할 수도 있습니다.