Skip to content

Relation one to one query results weird behavior  #195

Open
@filipe-carvalho

Description

@filipe-carvalho

Hi guys, bring some trouble again.

I've been facing some problems with one to one relations (one direction).
I have an entity ProjectDraft linked to Project, between an field published_project_id.

Here is the schema I am using:

ProjectDraft:
  actAs: { Timestampable: ~ }
  columns:
    name:               { type: string(100), notnull: true }
    project_state_id:   { type: integer}
    project_duration_id: { type: integer}
    published_project_id: { type: integer}
    
    address:            { type: string(255) }
    
  relations:
    Project:         { onDelete: CASCADE, class: Project, local: published_project_id, foreign: id, type: one }
    Scientist:       { onDelete: CASCADE, local: scientist_id, foreign: id, foreignAlias: Users, class: sfGuardUser } 
    State:           { onDelete: CASCADE, local: project_state_id, foreign: id, class: ProjectState } 



Project:
  actAs: { Timestampable: ~ }
  columns:
    name:               { type: string(100), notnull: true }
  relations:
    ProjectDraft:    { class: ProjectDraft, local: id, foreign: published_project_id, type: one, foreignType: one}

After this, I am trying to fetch one ProjectDraft object, trough this query:

$q = Doctrine_Query::create()
        ->from('ProjectDraft pd')
        ->leftJoin('pd.Project p')
        ->where('pd.id = 705')
        ->fetchOne();

Which gives me only ProjectDraft object, because published_project_id is NULL yet.
So far so good.

When I am trying to getProject, it gives me NULL, which is correct.

When I try to getProject()->exists() it give me Exception "Uncaught Error: Call to a member function exists() on null ", which is a king weird because exists() function return false, when we don't have a relation created.

After that, I trying to get_class of getProject, which should be Project or NULL or something like that (in my thoughts), but it give me the Class which I am debugging var, for instance, if you are in a projectAction class, it give me projectAction, it might be not normal this behavior I think.

I am thinking or I am doing anything wrong ?

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions