[DC-875] One-to-many relationship returns Doctrine_Record instead of Doctrine_Collection Created: 30/Sep/10 Updated: 14/Sep/11 |
|
| Status: | Open |
| Project: | Doctrine 1 |
| Component/s: | None |
| Affects Version/s: | 1.2.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Patrik Ã…kerstrand | Assignee: | Jonathan H. Wage |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Environment: |
WAMP: |
||
| Description |
|
I've run into a bit of a snag in my application where a relationship defined as a one-to-many relationship returns a model object (instance of Doctrine_Record) instead of a Doctrine_Collection when I try to access it as $model->RelatedComponent[] = $child1. This, of course, yields an exception like so: Doctrine_Exception: Add is not supported for AuditLogProperty }} This is what my yaml-schema looks like (excerpt): schema.yml AuditLogEntry:
tableName: audit_log_entries
actAs:
Timestampable:
updated: {disabled: true}
columns:
user_id: {type: integer(8), unsigned: true, primary: true}
id: {type: integer(8), unsigned: true, primary: true, autoincrement: true}
type: {type: string(255), notnull: true}
mode: {type: string(16)}
article_id: {type: integer(8), unsigned: true}
comment_id: {type: integer(8), unsigned: true}
question_id: {type: integer(8), unsigned: true}
answer_id: {type: integer(8), unsigned: true}
message_id: {type: integer(8), unsigned: true}
indexes:
# Must index autoincrementing id-column since it's a compound primary key and
# the auto-incrementing column is not the first column and we use InnoDB.
id: {fields: [id]}
type: {fields: [type, mode]}
relations:
User:
local: user_id
foreign: user_id
foreignAlias: AuditLogs
type: one
onDelete: CASCADE
onUpdate: CASCADE
AuditLogProperty:
tableName: audit_log_properties
columns:
auditlog_id: {type: integer(8), unsigned: true, primary: true}
prop_id: {type: integer(2), unsigned: true, primary: true, default: 1}
name: {type: string(255), notnull: true}
value: {type: string(1024)}
relations:
AuditLogEntry:
local: auditlog_id
foreign: id
type: one
foreignType: many
foreignAlias: Properties
onDelete: CASCADE
onUpdate: CASCADE
Now, if we look at the generated class-files, it looks fine: Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml /** * @property integer $user_id * @property integer $id * @property string $type * @property string $mode * @property integer $article_id * @property integer $comment_id * @property integer $question_id * @property integer $answer_id * @property integer $message_id * @property integer $news_comment_id * @property User $User * @property Doctrine_Collection $Properties * @property Doctrine_Collection $Notifications */ abstract class BaseAuditLogEntry extends Doctrine_Record /** * @property integer $auditlog_id * @property integer $prop_id * @property string $name * @property string $value * @property AuditLogEntry $AuditLogEntry */ abstract class BaseAuditLogProperty extends Doctrine_Record However, when I later try to add properties I get the exception posted in the beginning of the question: Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml $auditLog = new AuditLogEntry(); $prop1 = new AuditLogProperty(); $prop1->name = 'title'; $prop1->value = $this->Content->title; $prop2 = new AuditLogProperty(); $prop2->name = 'length'; $prop2->value = count($this->Content->plainText); $auditLog->Properties[] = $prop1; $auditLog->Properties[] = $prop2; $auditLog->save(); If I do the following: Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml var_dump(get_class($auditLog->Properties)); I get that Properties is of type AuditLogProperty, instead of Doctrine_Collection. I use version 1.2.3 of Doctrine. |
| Comments |
| Comment by Trevor Wencl [ 14/Sep/11 ] |
|
I am having the same issue and it is killing my application. Using your example, when I call:
... and there are no AuditLogProperty records, I would expect either an empty Doctrine_Collection or null, but instead I get a new instance of AuditLogProperty with null values for the properties. |