Git Product home page Git Product logo

Comments (9)

prajwalpoojari9876 avatar prajwalpoojari9876 commented on July 3, 2024 1

Yes I'm closing this. Thanks for the help.

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 3, 2024

What component are you referring to? Please provide a code example so that I can understand what you mean and replicate the behaviour.

from laravel-firebase.

prajwalpoojari9876 avatar prajwalpoojari9876 commented on July 3, 2024
$child = app('firebase.firestore')->database()->collection('Child')->newDocument();
$child->set([
      'name' => 'John',
]); 
$parent = app('firebase.firestore')->database()->collection('Parent')->newDocument();
$parent->set([
       'Child' => \Google\Cloud\Firestore\FieldValue::arrayUnion([$child->path()])
]);

OR

$parent = app('firebase.firestore')->database()->collection('Parent')->newDocument();
$parent->set([
       'Child' => $child->path()
]);

I want to set reference as datatype. Not string

from laravel-firebase.

prajwalpoojari9876 avatar prajwalpoojari9876 commented on July 3, 2024

Hi @jeromegamez, did you get my question?

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 3, 2024

Sorry for the late reply… unfortunately, I'm not super familiar with the Firestore component (this SDK just provides an entrypoint to google/cloud-firestore, but as far as I know it's not possible for a document to have a child - only collections can have children. You can see this in https://github.com/googleapis/google-cloud-php/blob/master/Firestore/src/DocumentReference.php#L70

So, if you wanted to have a reference between two documents, then using path strings and parsing them in your application would be the way to go.

I might be wrong - to be sure, I'd suggest asking the question again on StackOverflow or, if you think that this should be possible, as a feature request on https://github.com/googleapis/google-cloud-php/issues

I hope this helps!

from laravel-firebase.

prajwalpoojari9876 avatar prajwalpoojari9876 commented on July 3, 2024

ok @jeromegamez , thanks for all input you gave. it helps us in one or another way.

Now just to clear what we want to is send datatype of field.
As you can see in screenshot, there are many datatypes of a field. like from string, boolean etc.
There is one called "reference". We want to have this datatype.
As we send path, it always considered as string.

Screenshot_66

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 3, 2024

I just dug a little bit through the source code... could you try this?

$child = app('firebase.firestore')->database()->collection('Child')->newDocument();
$parent = app('firebase.firestore')->database()->collection('Parent')->newDocument();
$parent->set([
       'Child' => $child
]);

It looks like the Firestore library could be capable of resolving this correctly, see https://github.com/googleapis/google-cloud-php/blob/master/Firestore/src/ValueMapper.php#L310.

I don't know if the child document has to be saved beforehand though.

from laravel-firebase.

prajwalpoojari9876 avatar prajwalpoojari9876 commented on July 3, 2024

Thanks a lot @jeromegamez . It worked.

And I have checked the case the child document set method is to be called beforehand. Else it stores reference with child id but that child is not created.

from laravel-firebase.

jeromegamez avatar jeromegamez commented on July 3, 2024

🎉Glad I could help! Would it be okay for you if we close this issue?

from laravel-firebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.