Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation one to one query results weird behavior #195

Open
filipe-carvalho opened this issue Jul 5, 2018 · 0 comments
Open

Relation one to one query results weird behavior #195

filipe-carvalho opened this issue Jul 5, 2018 · 0 comments

Comments

@filipe-carvalho
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant