Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Parse, adding relation to object during signup

am attempting to associate a user with a company as they register. So, I am capturing the cony name upon registration, and I would like a column "createdby" in the midwifefirm that links a user to a company.

So, I have a register activity; realizing the Parse documentation uses CurrentUser to setup a pointer, I attempt to create the pointer in newUser.signUpInBackground(new SignUpCallback() {

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_midwife_register);

mPracticeName = (EditText) findViewById(R.id.enterpracticename);
mPrimaryContact = (EditText) findViewById(R.id.primarycontactnameField);
mPracticeEmail = (EditText) findViewById(R.id.createPracticeEmailEmailfield);
mPracticePassword = (EditText) findViewById(R.id.createmidwifepasswordfield);
mSignUpButton = (Button) findViewById(R.id.createmidwife);

mSignUpButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        //getting string values
        final String practicename = mPracticeName.getText().toString();
        String primarycontact = mPrimaryContact.getText().toString();
        String email = mPracticeEmail.getText().toString();
        String password = mPracticePassword.getText().toString();

        primarycontact = primarycontact.trim();
        email = email.trim();
        password = password.trim();

        if (practicename.isEmpty() || primarycontact.isEmpty() || email.isEmpty() || password.isEmpty()) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MidwifeRegisterActivity.this);
            builder.setPositiveButton(android.R.string.ok, null);

            AlertDialog dialog = builder.create();

        } else {
            //create new user
            ParseUser newUser = new ParseUser();

            newUser.put("primarycontact", primarycontact);
            newUser.put("userType", "midwife");

            mMidwiferyfirm = new ParseObject("midwifefirm");


            mMidwiferyfirm = new ParseObject("midwifefirm");

            mMidwiferyfirm.put("practicename", practicename);

            ParseACL roleACL = new ParseACL();

            ParseRole role = new ParseRole("Midwife", roleACL);



            newUser.signUpInBackground(new SignUpCallback() {
                public void done(ParseException e) {
                    if (e == null) {

                        mMidwiferyfirm.put("ownedby", ParseUser.getCurrentUser());


In the next activity, I want to be store more information about the company, but in the row associated with the current User:

mCreateButton.setOnClickListener(new View.OnClickListener() {

                                         public void onClick(View v) {

                                              final String streetaddress = mMidwifeStreetAddress.getText().toString();
                                              final String city = mMidwifeCity.getText().toString();
                                              final String midwifestate = mMidwifeState.getText().toString();
                                              final String midwifezip = mMidwifeZip.getText().toString();
                                              final String phone = mMidwifePhone.getText().toString();

                                             mMidwifeRelation = mMidwifefirm.getString("ownedby");

                                             ParseUser currentUser = ParseUser.getCurrentUser();

                                            mUserId = currentUser.getObjectId();

                                             ParseQuery<ParseObject> query = ParseQuery.getQuery("midwifefirm");
                                            query.whereEqualTo(mMidwifeRelation, mUserId);

                                            query.findInBackground(new FindCallback<ParseObject>() {
                                                public void done(List<ParseObject> list, ParseException e) {
                                                    mMidwifefirm.put("streetaddress", streetaddress);
                                                    mMidwifefirm.put("city", city);
                                                    mMidwifefirm.put("midwifestate", midwifestate);
                                                    mMidwifefirm.put("midwifezip", midwifezip);
                                                    mMidwifefirm.put("phone", phone);



                                             Intent intent = new Intent(MidwifeRegistrationAddress.this, MidwifeRegistrationPhilosophyActivity.class);



I don't think my way of getting the CurrentUser is working...I can't seem to get the "ownedby" field to be defined.

Any help would be appreciated.

Thanks so much