# How to create new row (relationship)?

**URL:** <https://www.ruby-forum.com/t/how-to-create-new-row-relationship/116973>\
**Category:** Rails\
**Created:** [October 11, 2007, 8:02pm UTC](https://www.ruby-forum.com/t/how-to-create-new-row-relationship/116973 "2007-10-11T20:02:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [October 11, 2007, 8:02pm UTC](https://www.ruby-forum.com/t/how-to-create-new-row-relationship/116973/1 "2007-10-11T20:02:11Z")

</div>

Hi,

I have some problems creating new rows based on relationship 🙂

I’m using has\_and\_belongs\_to\_many

Groups \<=\> ContactsGroups \<=\> Contacts

When I type in Irb this:  
Group.find(4).contacts

I get the following result, which is fine 😃  
=\> [#\<Contact:0x493afa4 @attributes={“accepted\_at”=\>nil…

But when I try to create new contact I get error ☹

Group.find(4).contacts.create  
=\> NoMethodError: undefined method `group\_id’

How can I create new contact through Group.find(4).contacts.create ?

Thanks for any response 😃

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [October 11, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/how-to-create-new-row-relationship/116973/2 "2007-10-11T20:15:53Z")

</div>

Having the same problem?

Just add to contacts in my case 😃

attr\_accessor :group\_id

It worked 🙂
